Search code examples
javascriptgoogle-apps-scripthttpresponseurlfetch

Converting httpresponse to main data or to html free data


I am on Google Apps script. Getting data using -

var httpresponse = UrlFetchApp.fetch(url); var httpData = httpresponse.getContentText();

Need to filter out data, rather than processing all HTML content in httpData, how to convert to data as we see on browser. Simply the main content. As if, when we open page on browser, select all, copy, and paste on notepad... that is what i mean by main content

is it feasible..?


Solution

  • after researching, i got What I wanted. adding a below line of code removes all the HTML tags.

    var realData = httpData.replace( /(<([^>]+)>)/ig, '');

    console.log(realdata)

    Although not perfect, it does remove 95% of the html.

    Another 100% working soln - using XmlService - https://developers.google.com/apps-script/reference/xml-service

    var doc = XmlService.parse(d5); var root = doc.getRootElement();