Cheerio / Node.JS - 检索元素

时间:2016-10-10 20:27:35

标签: javascript jquery node.js web-scraping cheerio

试图抓住此页面上的价格元素:

http://us.asos.com/asos/asos-bomber-jacket-in-khaki/prd/5773457?iid=5773457&affid=14174&channelref=product%20search&mk=abc&currencyid=2&gclid=CIvXk9DEt88CFYpehgodLo0Ivg

在运行console.log时无法获得任何建议吗?我已经检查过我选择了正确的元素。

var request = require('request');
var cheerio = require('cheerio');

var url = 'http://us.asos.com/asos/asos-bomber-jacket-in-khaki/prd/5773457?iid=5773457&affid=14174&channelref=product%20search&mk=abc&currencyid=2&gclid=CIvXk9DEt88CFYpehgodLo0Ivg';

request(url , function(error, response, html) {
if (!error && response.statusCode == 200) {
    var $ = cheerio.load(html); 


    $('span.current-price').each(function(i, element){
        console.log($(this).text());

    })

1 个答案:

答案 0 :(得分:0)

我在HTML中看到的current-price是:

<div class="current-price">

因此,$('span.current-price')与此不匹配。

你需要:

$('div.current-price')

或只是

$('.current-price')