我使用nightmare(phantomjs包装器)抓取网页,但我收到错误:
phantom stdout:TypeError:undefined不是构造函数(评估 '$(' 一个[HREF = “/二烯thoai /苹果iphone-6加64GB-BAN-杜国安-TE - pid975.html”] ')。得到(0).closest(' 部分') “)
var Nightmare = require('nightmare');
var bandcamp = new Nightmare()
.useragent("Mozilla/5.0 (Windows NT 6.3; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/38.0.2125.111 Safari/537.36")
.goto('http://viettelstore.vn/danh-muc/dien-thoai-010001.html#SpecOrder=')
.wait()
.click('a[href="/apple-mid1.html"]')
.wait()
.screenshot('viettelstore.png')
.evaluate(function () {
var x = $('a[href="/dien-thoai/apple-iphone-6-plus-64gb-ban-quoc-te--pid975.html"]').get(0).closest('section')
var y = $(x).find('.b-price.b-price_size3').find('.b-price__num').text()
return {name: y};
},function (value) {console.log(value.name);})
.run(function (err, nightmare) {
if (err) return console.log(err);
console.log('Done!');
});
点击后的页面屏幕快照符合预期。在浏览器的控制台中测试时,jquery代码运行正常。所以我认为问题来自phantomjs