how to fix Error The markup in the document preceding the root element must be well-formed

38 views Asked by At

I'm trying to parse html with parse library for google app script from github, but i get a Error to my code.

my code

function test() {

  options = {
    'method': 'post',
    'contentType': 'application/x-www-form-urlencoded',
    muteHttpExceptions: true
  };

  const url = 'https://www.n-vartovsk.ru/afisha/?DT_START=' + date_from() + '&DT_END=' + date_to() + '/';
  Logger.log(url);
  var html = UrlFetchApp.fetch(url).getContentText();
  Logger.log(html);
  var doc = XmlService.parse(html);
  var rootElement = doc.getRootElement();
  var parser = HtmlParser.of(rootElement);
  var res = parser.getElementsByTagName('a')

  for (var i = 0, n = res.length; i < n; i++) {
    var href = res[i].href;

    if (href.length) {

    }
  }

  Logger.log(href);

};

and i get an Error

Exception: Error on line 1: The markup in the document preceding the root element must be well-formed. test

how to fix it?

0

There are 0 answers