您好!欢迎来到聚码网

聚码网

热门搜索: 相亲小程序    搭子源码    直播系统自有商城   
  • node.js-node爬虫,request设置代理,总是报错求助
  • 聚码交流
  • 0 1
  • yhuxAvNbtxUM
    0000-00-00 00:00:00
  • 回帖
我用request爬取图片,为了防止ip被封,用了代理,可是用了代理后,总是报错。nodejs用到了request和async模块functiondownload(item,cb){request({url:item.img,proxy:proxys[Math.random()*proxys.length|0],method:'GET',timeout:5000},function(err,response,body){if(response&&response.statusCode==200){cb(null,item);}}).on('error',function(){console.log('下载出现异常,可能是pipe有问题,再次请求...');download(item,cb);//cb(null,item);}).pipe(fs.createWriteStream(fileDir2+item.name+'.'+item.url_token+'.jpg'));}download(item,cb),cb是async中控制流程的回调函数:async.eachLimit(items,10,function(item,cb){download(item,cb);},function(){...})每次下载没几个,就报错停止运行了:thrownewassert.AssertionError({^AssertionError:258==0atClientRequest.onConnect(C:\Users\fox\WebstormProjects\nodejs\实战\爬虫\node_modules\tunnel-agent\index.js:160:14)如果我去掉代理的请求头,一点事都没有;如果我把上面download里面,改成不再继续请求,直接cb(),请求失败不会报错。.on('error',function(){console.log('下载出现异常,可能是pipe有问题,再次请求...');//download(item,cb);cb(null,item);})请大佬看了,能不能帮我解决一下,想了很久,一直排错,不知道什么原因。
最近热帖
近期热议
联系我们
Q Q:317563994
电话:400-000-000
邮箱:317563994@qq.com
时间:09:00 - 17:00