ttripdee
ttripdee

Reputation: 31

Cheerio -Web Scraping - Not able to scrape innertext of a div

I am using Cheerio and request for web scraping. Below is my code on running which it doesn't give any error but also it doesn't gives me the innerText of div with that class name.

I am a beginner in this technology. So not able to figure out where i am missing something.

request(baseurl, function(err,resp,body) {
  if (!err && resp.statusCode == 200) {     
    var $ = cheerio.load(body);
    $('div.class','#EIGTDNC-d-W EIGTDNC-d-Lb EIGTDNC-d-S EIGTDNC-d-mb EIGTDNC-d-bc').each(function() {
      temp = this.attr('innerText');
      console.log(temp);
    });

    // send the message back to user
  }
  else {
    console.log('error:', err); 
    console.log('statusCode:', resp && resp.statusCode); 
  }
});
//dom closed

Upvotes: 2

Views: 7050

Answers (1)

WISeAgent
WISeAgent

Reputation: 31

innerText is not an attribute of this HTML element.

try retrieve the innerText value using an HTMLElement function:
temp = this.text()

Upvotes: 3

Related Questions