Google apps script to grab data from webpage

2019-07-05 14:29发布

I had help making this script before that would pull the playercount off a website and log it into spreadsheets with a date and timestamp, this was:

function pullRuneScape() {
  var page = UrlFetchApp.fetch('http://runescape.com/title.ws').getContentText();
  var number = page.match(/PlayerCount.*>([0-9,]+)</)[1];
  SpreadsheetApp.getActive().getSheetByName('RuneScape').appendRow([new Date(), number]);
}

Basically in the webpage they list the amount of players and I wanted to log it every 5minutes or so, but they have another site I wanted to grab the number from too and I need some help.

It's at http://oldschool.runescape.com/slu

I wanted to grab the player count on that site, at the top, and log it just like I have here: https://docs.google.com/spreadsheet/ccc?key=0AjrAPynUEUl9dGtIZFY0TlRFUllVcWFyZDZ2c2o5Tnc#gid=0

Where column A is the date and time, and B is just the number of people, so the output would be like 1/1/2013 0:00:48 77,439

Thank you if you can help.

1条回答
来,给爷笑一个
2楼-- · 2019-07-05 14:48

Read up on how to use regex. That will help you figure out what this code is doing. Please do not just copy the code that I have posted below. At Stack Overflow, we do not write code for you; we help you if something goes wrong.

var page = UrlFetchApp.fetch('http://oldschool.runescape.com/slu').getContentText();
var number = page.match(/There are currently ([0-9,]+)/)[1];
查看更多
登录 后发表回答