Google apps script to grab data from webpage

假装没事ソ 提交于 2019-12-10 10:27:25

问题


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:


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];


来源:https://stackoverflow.com/questions/15028614/google-apps-script-to-grab-data-from-webpage

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!