admin管理员组文章数量:1312658
Hi I'm trying to grab this webpage and store it into a table... any table. I'm using Google script.
var fetchString="/"
var response = UrlFetchApp.fetch(fetchString);
I need some help on the code to get this started. I'm looking to grab the "Traffic Data" table. I would like to put it into an 2D array if possible.
Hi I'm trying to grab this webpage and store it into a table... any table. I'm using Google script.
var fetchString="http://www.airchina..cn/www/en/html/index/ir/traffic/"
var response = UrlFetchApp.fetch(fetchString);
I need some help on the code to get this started. I'm looking to grab the "Traffic Data" table. I would like to put it into an 2D array if possible.
Share Improve this question edited Jun 23, 2017 at 15:38 Wicket 38.4k9 gold badges78 silver badges193 bronze badges asked Feb 11, 2013 at 3:38 jasonjason 4,47923 gold badges103 silver badges153 bronze badges1 Answer
Reset to default 7Google provides a XML parsing/manipulating service. You can use this to parse the html that is in that table.
One note, if you investigate where that html is actually ing from, you'll see that it's actually ing from a different url. http://www.airchina..cn/www/jsp/airlines_operating_data/exlshow_en.jsp
So here's what I got for you. It works pretty well. Hopefully this is enough of a start for you.
function fetchIt() {
var fetchString="http://www.airchina..cn/www/jsp/airlines_operating_data/exlshow_en.jsp"
var response = UrlFetchApp.fetch(fetchString);
var xmlDoc = Xml.parse(response.getBlob().getDataAsString(),true);
var b = xmlDoc.getElement().getElement("body");
var table = b.getElement("div").getElement("div").getElement("div").getElements("div")[1].getElement("table");
var rows = [];
var trs = table.getElements("tr");
for (var r=0,rlength=trs.length; r<rlength; r++) {
var tds = trs[r].getElements("td");
var row = [];
for (var c=0,clength=tds.length; c<clength; c++) {
row.push(tds[c].getText());
}
rows.push(row);
}
Logger.log(Utilities.jsonStringify(rows));
}
本文标签: javascriptgrabbing table from html using Google scriptStack Overflow
版权声明:本文标题:javascript - grabbing table from html using Google script - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1741912055a2404501.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论