nodejs抓取网页并使用jquery进行dom操作
安装依赖
npm install jquery
npm install jsdom
示例
const fs = require('fs');
const { JSDOM } = require('jsdom');
const jquery = require('jquery');
function get(url, callback) {
try {
JSDOM.fromURL(url).then(jsenv => {
const $ = jquery(jsenv.window);
const id_html = $('#dom_id').html();
callback(result);
});
} catch (e) {
console.log(e);
}
}
get('https://www.xxxx.com/xxx')