Google App script extracting data from website

随声附和 提交于 2019-12-01 09:15:21

问题


So I am writing a script which look at review done on google+ pages and updates a google spreadsheet.

I have found out that the line in the html which holds this value is

<span class="A7a">103</span> 

I just need to make it possible for me to extract from the page with just knowing the URL and that html code.


回答1:


Use

var response = UrlFetchApp.fetch("http://www.website.com/");

To fetch the html of the page. Then use something like

var cut = response.substring( str.indexOf( "<span class="A7a">" ), response.length);
var value = cut.substring(0, cut.indexOf("</span>"));

https://developers.google.com/apps-script/reference/url-fetch/url-fetch-app#fetch(String)




回答2:


I agree with the previous answer but there are some omissions

var response = UrlFetchApp.fetch(url);
var str = response.getContentText();
var balise = '<span class="A7a">'
var cut = str.substring(str.indexOf( balise ), response.length);
var value = cut.substring(balise.length, cut.indexOf("</span>"));


来源:https://stackoverflow.com/questions/22282344/google-app-script-extracting-data-from-website

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