我想抓住 http://www.euromillones.com.es/网站获得最后的5个数字和2个星.它可以在网站的左栏中看到.我一直在阅读教程,但我无法实现这一目标. 这是我到目前为止编写的代码: app.get('/winnern
这是我到目前为止编写的代码:
app.get('/winnernumbers', function(req, res){
//Tell the request that we want to fetch youtube.com, send the results to a callback function
request({uri: 'http://www.euromillones.com.es/ '}, function(err, response, body){
var self = this;
self.items = new Array();//I feel like I want to save my results in an array
//Just a basic error check
if(err && response.statusCode !== 200){console.log('Request error.');}
//Send the body param as the HTML code we will parse in jsdom
//also tell jsdom to attach jQuery in the scripts and loaded from jQuery.com
jsdom.env({
html: body,
scripts: ['http://code.jquery.com/jquery-1.6.min.js ']
}, function(err, window){
//Use jQuery just as in a regular HTML page
var $= window.jQuery;
res.send($('title').text());
});
});
});
我收到以下错误:
必须传递“已创建”,“已加载”,“已完成”选项或回调到jsdom.env.
在我看来,你刚刚使用了jsdom不知道如何处理的参数组合. documentation显示了这个签名:jsdom.env(string, [scripts], [config], callback);
两个中间参数是可选的,但您会注意到,所有可能的组合都以字符串开头,并以回调结束.文档提到了另一种调用jsdom.env的方法,那就是传递一个config参数.你在做什么相当于:
jsdom.env(config, callback);
这与任何记录的方法都不对应.我建议更改您的代码以传递单个配置参数.您可以将当前回调移动到该配置对象的done字段.像这样的东西:
jsdom.env({
html: body,
scripts: ['http://code.jquery.com/jquery-1.6.min.js'],
done: function (err, window) {
//Use jQuery just as in a regular HTML page
var $= window.jQuery;
res.send($('title').text());
}
});
