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,总是空行,为何?
来,上完整代码,解决了!
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){
var product_inventory=$(this).find("td.number").find("div#sp-stock_qty").text();
var product_group=$(this).find('td.group').text();
var product_desc=$(this).find("td.desc").text();
var product_info=$(this).find("td.description").find("b").text();
var product_price=$(this).find("td.price").find("div.price-box").find("span.regular-price").find("span.actualPrice").find("span.price").text();
console.log("---------------------------------------------------");
console.log("分组:"+product_group);
console.log("产品描述:"+product_desc);
console.log("产品全名:"+product_info);
console.log("价格"+product_price);
});
});
});