【发布时间】:2018-06-27 15:18:00
【问题描述】:
通过搜索查询后,我试图从 youtube 页面上的所有视频链接中抓取 href 属性值。
var casper = require('casper').create();
var links;
function getLinks() {
var links = document.querySelectorAll('div#contents div#dismissable a#thumbnail');
return Array.prototype.map.call(links, function (e) {
return e.getAttribute('href')
});
}
casper.start('https://www.youtube.com/results?search_query=a');
casper.then(function () {
links = this.evaluate(getLinks);
});
casper.run(function () {
for(var i in links) {
console.log(links[i]);
}
casper.done();
});
也是
div#contents div#dismissable a#thumbnail
抓取视频每个 a 标签的 href 属性的正确路径。
当我运行这段代码时,我得到一个错误提示
TypeError: undefined is not a constructor (evalating 'casper.done()')
C:/Users/rohit/Desktop/scraping codes/phantomjs:/code/test.js:24
C:/Users/rohit/Desktop/scraping codes/phantomjs:/platform/casper.js:423 in checkStep
【问题讨论】:
标签: javascript phantomjs casperjs