Node.js 僵尸错误-获取http请求时出错
我使用NodeJs和ZombieJS在虚拟浏览器环境中获取url请求 我正在使用以下代码:Node.js 僵尸错误-获取http请求时出错,node.js,zombie.js,Node.js,Zombie.js,我使用NodeJs和ZombieJS在虚拟浏览器环境中获取url请求 我正在使用以下代码: var zombie = require('zombie'), jsdom = require('jsdom'), my_sandbox = require('sandbox'), url = require('url'), http = require('http'), request = require('request'), httpProxy = require('./lib/node-http-
var zombie = require('zombie'),
jsdom = require('jsdom'),
my_sandbox = require('sandbox'),
url = require('url'),
http = require('http'),
request = require('request'),
httpProxy = require('./lib/node-http-proxy'),
des = '',
util = require('util'),
colors = require('colors'),
is_host = true;
var s = new my_sandbox();
var browser = new zombie.Browser;
httpProxy.createServer(9000, 'localhost').listen(8000);
function zombieFetching(page) {
browser.visit(page, { debug: false },
function(err, browser, status) {
if(err) {
console.log('There is an error. Fix it');
throw(err.message);
} else {
console.log('Browser visit successful') ;
}
});
}
var server = http.createServer(function (req, res) {
var pathname = '';
if(is_host) {
dest = req.url.substr(0, req.url.length);
pathname = dest;
is_host = false;
} else {
pathname = req.url.substr(0, req.url.length);
if(pathname.charAt(0) == "/") {
console.log('new request');
console.log(pathname);
pathname = dest + pathname;
}
}
request.get({uri: pathname}, function (err, response, html) {
console.log('The pathname is:::::::::: ' + pathname);
zombieFetching(pathname);
res.end(html);
});
});
server.listen(9000);
我在尝试获取url时看到以下错误:“www.yahoo.com”
据我所知,前四个get请求都成功了。
但是,我不确定为什么僵尸会获取无效的请求:
"http://www.yahoo.com/jserror?ad=1&target=cms&data=FPAD"
另外,是什么导致标记名错误中的无效字符
谢谢,
索尼
favicon.ico始终由浏览器请求;僵尸正在正确地模拟这种行为。它不在HTTP协议的任何地方,但这正是浏览器倾向于做的事情,所以他们会在地址栏中为支持它的站点显示一个漂亮的图标。您可能看到了jserror?
请求,因为僵尸在某个时候收到了指向该URL的301(重定向),并盲目地跟踪它,或者页面上的其他元素正在引用它。默认情况下,僵尸的处理程序会尝试跟踪所有内容,这就是为什么会像浏览器一样获取图像等等
如果您设置browser.debug=true
我想您可以获得比日志语句提供的信息多得多的信息。如果我请求url:,错误日志是:throw(err.message);^无法在加载资源,获取404。此url无效,我不确定提取此请求的原因。我不确定这是否是节点/僵尸中的错误,或者我的代码中是否有错误。
The pathname is:::::::::: http://www.yahoo.com/
The pathname is:::::::::: http://l1.yimg.com/a/i/ww/news/2011/05/06/zuckhouse-sm.jpg
The pathname is:::::::::: http://l1.yimg.com/a/i/ww/news/2011/05/07/cable-sm.jpg
The pathname is:::::::::: http://l.yimg.com/a/a/1-/flash/promotions/yahoo/081120/70x50iltlb_2.jpg
Browser visit successful
Browser visit successful
Browser visit successful
Browser visit successful
The pathname is:::::::::: http://l.yimg.com/a/i/vm/2011may/bird74.jpg
The pathname is:::::::::: http://www.yahoo.com/jserror?ad=1&target=cms&data=FPAD
"http://www.yahoo.com/jserror?ad=1&target=cms&data=FPAD"