Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Google apps script to grab data from webpage

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.

like image 584
Aaron Avatar asked Oct 19 '25 15:10

Aaron


1 Answers

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];
like image 172
Phil Bozak Avatar answered Oct 22 '25 08:10

Phil Bozak



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!