Warm tip: This article is reproduced from serverfault.com, please click

Node.js scrape with cheerio return no value

发布于 2020-12-24 20:15:00

I'm trying to automate a task of mine with Node.js, trying to find the winning numbers on the local car lotto.

When I'm trying to parse the results, I get nothing back.

here is my try:

const rp = require('request-promise');
const $ = require('cheerio');
const url = 'https://www.otpbank.hu/portal/hu/Megtakaritas/ForintBetetek/Gepkocsinyeremeny';

rp(url)
 .then(function(html) {
   console.log($('.list-item list-item--primary ul li', html).text());
 })
 .catch(function(err) {
   //handle error
 });
Questioner
fagylalt
Viewed
0
Or Assayag 2020-12-25 04:32:55

Since the 'list-item--primary' is already li element, try:

const rp = require('request-promise');
const cheerio = require('cheerio');
const url = 'https://www.otpbank.hu/portal/hu/Megtakaritas/ForintBetetek/Gepkocsinyeremeny';

rp(url)
 .then(function(html) {
    const $ = cheerio.load(html);
    let data = [];
    $('.list-item--primary').map((i,elm) => {
        console.log(elm.innerText);
    });
 })
 .catch(function(err) {
   //handle error
 });