您的位置:首页 > Web前端 > JavaScript

用Nightmarejs 获取百度搜索结果数量

2017-11-14 10:06 411 查看
const Nightmare = require('nightmare');
const nightmare = Nightmare({
typeInterval: 500,
//openDevTools: {mode: 'detach'},
show: true });

nightmare
.goto('https://www.baidu.com')
.type('input#kw', 'github')
.click('input#su')
.wait('div.nums')
.evaluate(() => document.querySelector('div.nums').innerHTML)
.end()
.then((text) => { // This will log the your local IP
console.log('search: %s result.', text.match(/[\d,]+/)[0]);
})
.catch((error) => {
console.error('Search failed:', error);
});

//console.log(nightmare.engineVersions());

目前的输出:search: 68,200,000 result.
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签:  nightmarejs