1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26
| #!/usr/bin/env node
var cheerio = require('cheerio'), request = require('request'), colors = require('colors'), printf = require('printf'), dateFormat = require('dateformat'); request("http://www.example.com/goods/show/99", function(error, response, html) { if (error) { return console.error(error); }
var $ = cheerio.load(html); var name = $("table.jmb tr").eq(2).find("td span").first().text().trim(); var price = $("table.jmb tr").eq(2).find("td span").last().text().trim().match(/(\d+).*=.*\s(\d+).*=.*/); var price1b = price[1]; var price10b = price[2];
console.log(printf( "%-30s %-30s %-30s %-20s %-30s", "Example", price1b, price10b, +Date.now(), dateFormat(Date.now(), "yyyy-mm-dd HH:mm::ss") )); });
|