噩梦/电子:导航错误(代码-118) [英] Nightmare / Electron : Navigation Error (code - 118)
问题描述
用噩梦刮擦一直很容易,直到最近,我开始遇到没有详细信息的错误,标题为导航错误
,错误代码为118,如下所示。
{[错误:导航错误]
'0':
{消息:'导航错误',
代码:-118,
详细信息:'',
网址:' http://markets.ft.com/research/Browse-Companies '},
长度:1,
错误:
[{消息:导航错误,
代码:-118,
详细信息:,
网址: http://markets.ft.com/research/Browse-Companies '}]}
我的噩梦代码(Node.Js):
函数* run(){
var nightmare =噩梦({show:true});
nightmare.useragent( Mozilla / 5.0(Windows NT 6.1)AppleWebKit / 537.36(KHTML,如Gecko)Chrome / 41.0.2228.0 Safari / 537.36)
var url = http:// markets。 ft.com/research/Browse-Companies;
var industry = [];
//以{INDUSTRY,LINK,SECTOR}格式获取数据。
产生噩梦.goto(url).inject('js','./jquery-2.2.3.min.js').wait('#wsod').evaluate(function() {
var arr = [];
$('。simpleLinkList.wsodModuleContent li')。each(function(){
arr.push({SECTOR :$(this).parents('ul')。prev()。text()。replace('Sectors& Industries',''),
Industry:$(this).text(),LINK :$(this).find('a')。attr('href')});
})
return arr;
})。 then(function(data){
industry = data;
});
//使用{LINK}
var companies = [];
for(var i = 0; i< 2; i ++)
{
产生收益的噩梦.goto(industry [i] .LINK).inject(' js','./jquery-2.2.3.min.js').wait('#wsod');
var nextExists =产生噩梦.visible(’。wsod-icon-paging-next-active’);
var maxpage = 3;
var currentpage = 1;
var data = []; / * Object({Name:,Link:})* /
while(nextExists&& currentpage< maxpage)
{
//分页/检查下一页是否存在,并为每页循环抓取器
产生噩梦.evaluate(function(a,b){
var obj = [];
$(' .company-link')。each(function(){
obj.push({Sector:a,Industry:b,Name:$(this).text(),Link:$(this).attr( 'href')});
});
return obj;
},industry [i] .SECTOR,industry [i] .INDUSTRY).then(function( obj){
data.push(obj);
});
收益噩梦.click(’。wsod-icon-paging-next-active’)。wait(2000);
当前页++;
nextExists =产生噩梦.visible(’。wsod-icon-paging-next-active’);
}
//数据是一个数组数组,需要进行展平。
var x = [] .concat.apply([],data);
//现在将数据推送到公司列表(整个容器)
companies.push(x);
}
公司= [] .concat()。apply([],公司);
//现在公司是每个部门中所有公司的完整列表的数组->行业,其中包括部门名称,以方便地使用
console.log(companies); * /
console.log(companies);
收益噩梦.end();
}
如果有人可以提供有关此错误的更多信息,它将很棒。该程序有时会工作,但大多数情况下,在通过Chrome文档进行了一些研究之后,我会收到导航错误
好的错误代码-118与超时有关,但是此问题在立即加载到实际Chrome浏览器上的网站上弹出。
现在好像是一个电子小虫,如果有人知道更多,请提供详细信息。
Scraping with nightmare has been a breeze until recently , i started encountering errors with no details and the title "navigation error" and the error code 118 as shown below.
{ [Error: navigation error]
'0': { message: 'navigation error', code: -118, details: '', url: 'http://markets.ft.com/research/Browse-Companies' }, length: 1, errors: [ { message: 'navigation error', code: -118, details: '', url: 'http://markets.ft.com/research/Browse-Companies' } ] }
My nightmare code (Node.Js) :
function *run(){
var nightmare = Nightmare({show : true });
nightmare.useragent("Mozilla/5.0 (Windows NT 6.1) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/41.0.2228.0 Safari/537.36")
var url = "http://markets.ft.com/research/Browse-Companies";
var industry = [];
//fetching data in { INDUSTRY , LINK , SECTOR } format .
yield nightmare.goto(url).inject('js' , './jquery-2.2.3.min.js').wait('#wsod').evaluate(function () {
var arr = [];
$('.simpleLinkList.wsodModuleContent li').each(function(){
arr.push({SECTOR : $(this).parents('ul').prev().text().replace('Sectors & Industries' , '') ,
INDUSTRY : $(this).text() , LINK : $(this).find('a').attr('href')});
})
return arr;
}).then(function (data) {
industry = data;
});
//using {LINK}
var companies = [];
for(var i = 0 ; i<2; i++)
{
yield nightmare.goto(industry[i].LINK).inject('js' , './jquery-2.2.3.min.js').wait('#wsod');
var nextExists = yield nightmare.visible('.wsod-icon-paging-next-active');
var maxpage = 3;
var currentpage = 1;
var data = []; /* Object({ Name: "" , Link : ""})*/
while(nextExists && currentpage < maxpage)
{
//pagination / checking if next page exists and looping the scraper for each page
yield nightmare.evaluate(function(a , b){
var obj = [];
$('.company-link').each(function () {
obj.push({Sector : a , Industry: b , Name: $(this).text() , Link: $(this).attr('href')});
});
return obj;
},industry[i].SECTOR , industry[i].INDUSTRY).then(function (obj) {
data.push(obj);
});
yield nightmare.click('.wsod-icon-paging-next-active').wait(2000);
currentpage++;
nextExists = yield nightmare.visible('.wsod-icon-paging-next-active');
}
//data is an array of arrays and needs to be flattened.
var x = [].concat.apply([] , data);
//now pushing data to companies list (entire container)
companies.push(x);
}
companies = [].concat().apply([], companies);
//now companies is an array of entire list of all companies in every single sector->industry with sector name included for ease
console.log(companies);*/
console.log(companies);
yield nightmare.end();
}
If anyone could provide more info regarding this error , it would be great . The program works some times but most times i get the "Navigation-error"
Alright , after some research through the chromium docs which powers electron+nightmare .
Error code -118 relates to a time-out , however this issue pops up on websites that load instantly on a real chromium browser .
Seems like an electron bug for now , if anyone knows more please do provide the details.
这篇关于噩梦/电子:导航错误(代码-118)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!