我不断收到的错误消息如下:
assert.js:92
throw new assert.AssertionError({
^
AssertionError: abnormal phantomjs exit code: -1073741819
at Console.assert (console.js:102:23)
at ChildProcess.<anonymous> (C:\Users\file_path...\node_modules\phantom\phantom.js:132:28)
at ChildProcess.emit (events.js:98:17)
at Process.ChildProcess._handle.onexit (child_process.js:810:12)
Program node app.js exited with code 8
中断是随机发生的,有时是在插入一千多行到postgreSQL之后,有时候只是在几行之后。
基于我在整个代码中放置的许多不同的console.log,我相当确定我的代码中的以下函数中发生了错误。另外,我认为assert.js:92
来自Chai:
function getNetworkTraffic(networkUrl,senderEmail) {
phantom.create(function (ph) {
ph.createPage(function (page) {
page.set("onResourceRequested", function (req) {
referrerValue = "";
referrerName = "";
linkRedirectUrl="";
console.log('Fetching network traffic...')
for (i in req.headers) {
allReferrals = req.headers[i]
if (allReferrals.name == "Referer"){
referrerName = allReferrals.name
referrerValue = allReferrals.value
}
}
linkUrl = req.url
if(req.redirectURL){
linkRedirectUrl = redirectURL
}
singleReq = {"referrerName":referrerName,"referrerValue":referrerValue,"requestUrl":linkUrl,"redirectURL":linkRedirectUrl, "parent_url":networkUrl, "source": "email", "senderEmail":senderEmail}
// insertNetworkTrafficPg(singleReq)
});
page.set("onResourceReceived", function (res) {
linkRedirectUrl = "";
responseUrl = res.url
if(res.redirectURL){
linkRedirectUrl = res.redirectURL
}
singleRes = {"responseUrl":responseUrl,"redirectURL":linkRedirectUrl,"parent_url":networkUrl,"source": "email", "senderEmail":senderEmail}
// insertNetworkTrafficPg(singleRes)
});
try{
page.open(networkUrl, function (status) {
if (status !== 'success') {
console.log('FAIL to load the address');
}
console.log('Opening web address...');
ph.exit();
});
} catch(err) {
console.log(err)
}
});
}, {
dnodeOpts: {
weak: false
}
});
}
答案 0 :(得分:1)
可以将phantomjs与节点一起使用,但请记住,这是一个桥梁。此外,它真的不是为了大量的抓取,所以也许你打开太多的线程和它的堆栈溢出,但打破另一个消息。您可能想尝试使用python-shell之类的东西来运行python脚本来进行抓取。