首页 > 解决方案 > Nokogiri 和 Open-Uri 的警告消息

问题描述

您好,我有一条错误消息,如下所示:

警告:不推荐通过 Kernel#open 调用 URI.open,直接调用 URI.open 或使用 URI#open

我不明白为什么会出现此消息,我也尝试了 URI.open ("link") 命令。读

但我必须使用 Nokogiri。

这是我的代码:

require 'nokogiri'
require 'open-uri'


puts "Wait a second data is coming..."


PAGE_URL = "https://coinmarketcap.com/all/views/all/"

page = Nokogiri::HTML(open(PAGE_URL))


currency_name_array = page.xpath("//tr/td/a[contains(@class, 'currency-name-container')]/text()").map {|x| x.to_s }

currency_value_array = page.xpath("//tr/td/a[contains(@class, 'price')]/text()").map {|x| x.to_s }


currency_result = Hash[currency_name_array.zip(currency_value_array)]

puts currency_result

提前致谢。

标签: rubynokogiriwindows-subsystem-for-linuxopen-uri

解决方案


推荐阅读