我正在使用 phantomjs 学习如何抓取网页,到目前为止我已经开发了以下代码..我知道我能够连接到该网站,但我根本无法从表中获取数据..am我走在正确的轨道上吗?
我的目标是从表中抓取数据this地点。我还知道我需要使用 includeJs 或injectJs 来等待表加载,否则我将抓取一个空的 html 页面。我正在尝试将这些概念放在一起,但现在已经被困了 3 天多了..请给予一些指导..
var page = require('webpage').create();
console.log('Welcome to scraping...');
page.open('http://www.inc.com/inc5000/index.html', function(status) {
page.includeJs("http://ajax.googleapis.com/ajax/libs/jquery/1.6.1/jquery.min.js", function() {
if (status !== 'success') {
console.log('Unable to access network');
} else {
var ua = page.evaluate(function() {
var DATA = [];
var res= document.getElementById((this).find('td')).eq(0).text();
console.log(res); //**See output below for what is happening here**
$('tr.ng-scope').each(function(){
var $tds = $(this).find('td');
DATA.push({
rank: $tds.eq(0).text(),
company: $tds.eq(1).text(),
growth: $tds.eq(2).text(),
revenue: $tds.eq(3).text(),
industry: $tds.eq(4).text()
});
});
console.log(DATA);
console.log('Got into func');
//return document.getElementById('myagent').textContent;
});
console.log('Got out of function');
console.log(ua);
}
phantom.exit();
});
});
我得到的输出是:
欢迎大家来刮...
ReferenceError:找不到变量:角度
http://stage.inc.com/js/Inc5000ListApp.js?UPDATE1:2
http://www.inc.com/inc5000/index.html:2485
类型错误:'null'不是对象(评估'document.getElementById(this.find('td')).eq')
phantomjs://webpage.evaluate():3 //这是什么意思?
phantomjs://webpage.evaluate():20
phantomjs://webpage.evaluate():20
失去功能
null
None
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)