Friday 17 March 2017

Event handler in Parsing a webpage

I have a function in .js file where I have following function which takes a url (one by one from where it is getting called), calls http.get and then parses the received webpage. I have to parse the webpage to get 'A' tags and subsequently the href attribute.

Problem: function parser.on('startTag'...) never gets called as I have tried detecting it using printing "in this func". Can't figure out why is this.

const http = require('http')
const https = require('https')
const parse5 = require('parse5');
const req = async link => {
    try {
         response = await https.get(link)
         console.log(`data recived for ${link}`)
         const parser = new parse5.SAXParser();
         parser.on('startTag', (p1,p2) => {
             console.log('in this func')
     })
     myparser = response.pipe(parser)
}
    catch (err) {
         console.log(err)
   }

}



via Manahil

No comments:

Post a Comment