Cheerio: How to iterate divs and extract text

Created on 1 Jan 2018  Â·  3Comments  Â·  Source: cheeriojs/cheerio

I really don't why I am getting undefined while my jquery code seems to be perfect

    const request = require('request');
    const cheerio = require('cheerio');
    const fs = require('fs');


    request('https://www.goodreads.com/quotes/tag/entrepreneurship?page=1', function (error, response, body) {

        const $ = cheerio.load(body);

        let data = [];

        $('.quoteText').map((i,elm) => {

            console.log(elm.innerText) //undefined

        })

    });

Most helpful comment

Not working

All 3 comments

use

console.log($(elem).text());

https://github.com/cheeriojs/cheerio#text-textstring-

Not working

what doesn't work?

âžś css-select-test git:(master) âś— node

const request = require('request');
undefined
const cheerio = require('cheerio');
undefined
const fs = require('fs');
undefined

request('https://www.goodreads.com/quotes/tag/entrepreneurship?page=1', function (error, response, body) {
...
... const $ = cheerio.load(body);
...
... let data = [];
...
... $('.quoteText').map((i,elm) => {
... console.log($(elm).text())
... })
... });

  “If you want to build a ship, don’t drum up the men to gather wood, divide the work, and give orders. Instead, teach them to yearn for the vast and endless sea.”
―
Antoine de Saint-Exupéry
  “Rejection is an opportunity for your selection.”
―
Bernard Branson

.....

Was this page helpful?
0 / 5 - 0 ratings

Related issues

unicrus picture unicrus  Â·  4Comments

robogeek picture robogeek  Â·  4Comments

kminehart picture kminehart  Â·  5Comments

Canop picture Canop  Â·  3Comments

gajus picture gajus  Â·  4Comments