grabbing table from html using Google script

前端 未结 1 1807
南方客
南方客 2020-12-10 20:55

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.com.cn/www/en/htm         


        
1条回答
  •  無奈伤痛
    2020-12-10 21:51

    Google 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 coming from, you'll see that it's actually coming from a different url. http://www.airchina.com.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.com.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

    0 讨论(0)
提交回复
热议问题