请教node-jquery的用法?
发布于 12 年前 作者 hunk 12157 次预览 最后一次回复是 12 年前 来自
var $ = require(‘jquery’); $.get(“http://www.windeln.de/hipp-milchnahrung-combiotik.html”,function(html){ var $doc = $(html); $doc.find(".clickable-tr").each(function(project){ var $project = $(project); console.log($project);
输出project,总是空行,为何?
4 回复
用jsdom 比node-jquery 强。。
也用 jsdom
这代码跑不起来的吧, 花括号都没全… 都看不出来怎么执行的
来,上完整代码,解决了!
var $ = require(‘jquery’); var http = require(‘http’); var options = { host: ‘www.windeln.de’, port: 80, path: ‘/hipp-milchnahrung-combiotik.html’, headers: {‘user-agent’: ‘Mozilla/5.0’} };
var html = ‘’; http.get(options, function(res) { res.on(‘data’, function(data) { // collect the data chunks to the variable named "html" html += data; }).on(‘end’, function() { // the whole of webpage data has been collected. parsing time! var item = $(html).find(‘tr.clickable-tr’).each(function($this){
});