What is the best way to parse html in google apps script

后端 未结 6 1940
刺人心
刺人心 2020-11-30 03:08
var page = UrlFetchApp.fetch(contestURL);
var doc = XmlService.parse(page);

The above code gives a parse error when used, however if I replace the

6条回答
  •  情书的邮戳
    2020-11-30 04:01

    I know it is not exactly what OP asked, but I found this question when I was looking for some html parsing options - so it might be useful for others as well.

    There is an easy to use the library for TEXT parsing. It's useful if you want to get only one piece of information from the html(xml) code.

    It works like in the picture above

    function getData() {
        var url = "https://chrome.google.com/webstore/detail/signaturesatori-central-s/fejomcfhljndadjlojamaklegghjnjfn?hl=en";
        var fromText = '';
    
        var content = UrlFetchApp.fetch(url).getContentText();
        var scraped = Parser
                        .data(content)
                        .from(fromText)
                        .to(toText)
                        .build();
        Logger.log(scraped);
        return scraped;
    }
    

提交回复
热议问题