Answer the question
In order to leave comments, you need to log in
Why doesn't it output html when parsing a web page, but outputs an object??
Here is an example:
const request = require('request-promise');
const cheerio = require('cheerio');
const options = {
url: 'https://www.php.net/manual/ru/function.get-browser.php',
headers: {
'User-Agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/74.0.3729.169 Safari/537.36'
}
};
function callback (error, response, html) {
if (!error && response.statusCode == 200) {
return html;
} else {
console.log("error has occured");
console.log(error);
}
}
module.exports = function webData () {
try {
const page = request.get(options, callback);
var $ = cheerio.load(page);
var h1 = $('h1.refname');
console.log(h1);
} catch(err) {
console.log(err);
}
}
Answer the question
In order to leave comments, you need to log in
because $('h1.refname') returns a jQuery object. use something like $('h1.refname').get(0).innerHTML
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question