首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >未显示Nokogiri价格

未显示Nokogiri价格
EN

Stack Overflow用户
提问于 2019-03-22 05:46:32
回答 1查看 38关注 0票数 1

谁能解释一下如何使用nokogiri检索价格的值?出现在我创建的刮板上的值是this

代码语言:javascript
复制
Costa Rica
<span class="ProductListElement__price"> </span>
India
<span class="ProductListElement__price"> </span>
Indonesia
<span class="ProductListElement__price"> </span>
Colombia
<span class="ProductListElement__price"> </span>
Nicaragua
<span class="ProductListElement__price"> </span>
Ethiopia
<span class="ProductListElement__price"> </span>
Master Origin Pack (50 cápsulas)
<span class="ProductListElement__price"> </span>
CAFÉ İSTANBUL
<span class="ProductListElement__price"> </span>
Envivo Lungo
<span class="ProductListElement__price"> </span>
Fortissio Lungo
<span class="ProductListElement__price"> </span>
Vivalto Lungo
<span class="ProductListElement__price"> </span>
Linizio Lungo
<span class="ProductListElement__price"> </span>
Livanto
<span class="ProductListElement__price"> </span>
Capriccio
<span class="ProductListElement__price"> </span>
Volluto
<span class="ProductListElement__price"> </span>
Cosi
<span class="ProductListElement__price"> </span>
Kazaar
<span class="ProductListElement__price"> </span>
Dharkan
<span class="ProductListElement__price"> </span>
Ristretto
<span class="ProductListElement__price"> </span>
Arpeggio
<span class="ProductListElement__price"> </span>
Roma
<span class="ProductListElement__price"> </span>
Ristretto Decaffeinato
<span class="ProductListElement__price"> </span>
Arpeggio Decaffeinato
<span class="ProductListElement__price"> </span>
Volluto Decaffeinato
<span class="ProductListElement__price"> </span>
Vivalto Lungo Decaffeinato
<span class="ProductListElement__price"> </span>
Vanilio
<span class="ProductListElement__price"> </span>
Caramelito
<span class="ProductListElement__price"> </span>

我的控制器是这样的:

代码语言:javascript
复制
class CupsController < ApplicationController

    class Entry
      def initialize(name, price)
        @name = name
        @price = price

      end
      attr_reader :name
      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
            price = entry.css('span.ProductListElement__price')


          @entriesArray << Entry.new(name, price)
          @name = name
          @price = price

        end
        render template: 'cups/home'
    end
end
EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2019-03-25 00:18:18

这是我收到的每个结果的结果:

代码语言:javascript
复制
<span class="ProductListElement__price"> </span>

这向我表明,一旦网页加载,价格就会由JavaScript动态加载。

为了能够抓取动态加载的数据,您需要使用诸如Watir之类的库,这是Rails5所支持的。

使用Watir,您可以在尝试抓取站点之前等待所有脚本执行完毕并加载所有数据。

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/55289737

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档