M
M
mitra_mc2018-10-29 00:10:31
Parsing
mitra_mc, 2018-10-29 00:10:31

Why can't parse an element from a webpage?

Hello. I'm trying to parse a block, but it returns null. What can be wrong?

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

request('https://vk.com/durov', (err, res, html) => {
  if (!err && res.statusCode == 200) {
    const $ = cheerio.load(html);

    const nameElement = $('.page_block');

    console.log(nameElement.html());
  }
});

Answer the question

In order to leave comments, you need to log in

1 answer(s)
Q
qq1, 2018-10-29
@qq1

You need to add a user-agent header:

let headers = {
  'User-Agent': 'Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/70.0.3538.67 Safari/537.36'
}
request({url: 'https://vk.com/durov', headers}, (err, res, html) => {
})

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question