我正试图找回this网站的价格。我正在使用nokogiri,这是我的控制器:
class CupsController < ApplicationController
class Entry
def initialize(name, info, link, price)
@name = name
@info = info
@link = link
@price = price
end
attr_reader :name
attr_reader :info
attr_reader :link
attr_reader :price
end
def cups
require 'open-uri'
require 'nokogiri'
doc = Nokogiri::HTML(open('https://www.nespresso.com/pt/pt/order/capsules'))
entries = doc.css('article.ProductListElement')
@entriesArray = []
entries.each do |entry|
name = entry.css('.ProductListElement__name').text
info = entry.css('.ProductListElement__information').text
link = entry.css('.ProductListElement__link').map { |link| link['href'] }.try(:[], 0)
price = entry.css('span.ProductListElement__price').text
@entriesArray << Entry.new(name, info, link, price)
@name = name
@info = info
@link = link
@price = price
end
render template: 'cups/home'
end
end
价格的css在此行上,使用检查器“ ProductListElement__price”>€0.44 但是显示其空白的价格。谁能解释为什么?