1
我下面的教程这里列出抄袭:与phantomJS和的NodeJS
http://code.tutsplus.com/tutorials/screen-scraping-with-nodejs--net-25560
当我运行代码:
var host = 'http://www.shoutcast.com/?action=sub&cat=Hindi#134';
var phantom = require('phantom');
phantom.create(function(ph) {
return ph.createPage(function(page) {
return page.open(host, function(status) {
console.log("opened site? ", status);
page.injectJs('http://ajax.googleapis.com/ajax/libs/jquery/1.11.0/jquery.min.js', function() {
//jQuery Loaded.
//Wait for a bit for AJAX content to load on the page. Here, we are waiting 5 seconds.
setTimeout(function() {
return page.evaluate(function() {
//Get what you want from the page using jQuery. A good way is to populate an object with all the jQuery commands that you need and then return the object.
console.log(document.getElementsByClassName('transition')[0]);
return document.getElementsByClassName('transition')[0];
}, function(result) {
console.log(result);
ph.exit();
});
}, 5000);
});
});
});
});
我得到以下错误:
phantom stdout: ReferenceError: Can't find variable: $
phantom stdout: phantomjs://webpage.evaluate():7
phantomjs://webpage.evaluate():10
phantomjs://webpage.evaluate():10
我不知道这是什么意思,并没有帮助如何解决它... 这怎么解决?
基本上我希望所有的'a'标签有从我正在刮的网站的类转换。所有这些标签都在网站上异步加载。
变量'h2Arr'从哪里来?在你展示的代码片段中,它不会在任何地方初始化。 – Stilltorik
我刚更新了代码和错误。以前的代码来自旧的提交。 –