[英]Cheerio / Node.JS - retrieving an element
嘗試在此頁面上抓取價格元素:
運行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¤cyid=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());
})
我在HTML中看到的current-price
是這樣的:
<div class="current-price">
因此, $('span.current-price')
將$('span.current-price')
不符。
你需要:
$('div.current-price')
要不就
$('.current-price')
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.