Вот пример:
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);
}
}
Результат:
initialize {
options: {
withDomLvl1: true,
normalizeWhitespace: false,
xml: false,
decodeEntities: true
},
_root: initialize {
'0': {
type: 'root',
name: 'root',
namespace: '
www.w3.org/1999/xhtml',
attribs: [Object: null prototype] {},
'x-attribsNamespace': [Object: null prototype] {},
'x-attribsPrefix': [Object: null prototype] {},
children: [Array],
parent: null,
prev: null,
next: null
},
options: {
withDomLvl1: true,
normalizeWhitespace: false,
xml: false,
decodeEntities: true
},
length: 1,
_root: [Circular]
},
length: 0,
prevObject: initialize {
'0': {
type: 'root',
name: 'root',
namespace: '
www.w3.org/1999/xhtml',
attribs: [Object: null prototype] {},
'x-attribsNamespace': [Object: null prototype] {},
'x-attribsPrefix': [Object: null prototype] {},
children: [Array],
parent: null,
prev: null,
next: null
},
options: {
withDomLvl1: true,
normalizeWhitespace: false,
xml: false,
decodeEntities: true
},
length: 1,
_root: [Circular]
}
}