问题描述
在制作此脚本之前,我曾提供过帮助,可以将玩家人数从网站上提取下来,并将其登录到带有日期和时间戳的电子表格中,这是:
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]);
}
基本上,他们在网页上列出了玩家数量,我想每5分钟左右记录一次,但他们也有另一个网站,我也想从中获取人数,我需要一些帮助.
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.
它位于 http://oldschool.runescape.com/slu
我想在该网站的顶部获取玩家人数,并像在这里一样记录它: https://docs.google.com/spreadsheet/ccc?key=0AjrAPynUEUl9dGtIZFY0TlRFUllVcWFyZDZ2c2o5Tnc#gid=0
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
A列是日期和时间,B列是人数,因此输出将类似于1/1/2013 0:00:48 77,439
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
谢谢您的帮助.
推荐答案
阅读有关如何使用正则表达式的信息.这将帮助您弄清楚这段代码在做什么.请不要只复制我在下面发布的代码.在Stack Overflow,我们不会为您编写代码.如果出现问题,我们会为您提供帮助.
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];
这篇关于Google Apps脚本可从网页获取数据的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!