Does Google Apps Script have something like getElementById?

前端 未结 3 614
温柔的废话
温柔的废话 2020-12-06 08:04

I am gonna to use Google App Script to fetch the programme list from the website of radio station. How can I select the specified elements in the webpage by specifying the i

3条回答
  •  死守一世寂寞
    2020-12-06 08:29

    Someone has made an example here where the following custom functions are available for cut & paste use:

    • getElementById()
    • getElementsByClassName()
    • getElementsByTagName()

    Then you can do something like this

    function doGet() {
      var html = UrlFetchApp.fetch('http://en.wikipedia.org/wiki/Document_Object_Model').getContentText();
      var doc = XmlService.parse(html);
      var html = doc.getRootElement();
      var menu = getElementsByClassName(html, 'menu-classname')[0];
      return menu;
    }
    

提交回复
热议问题