【发布时间】:2014-11-16 01:55:51
【问题描述】:
我是 ruby 编码的新手,我想知道为什么在运行下面的代码时会收到警告。
我检查了一些类似问题的答案,但似乎无法让它对我有用。
您知道为什么会发生这种情况以及如何解决吗?
非常感谢!
这是我在终端中收到的警告
test_Amazon.rb:9: warning: already initialized constant PAGE_URL
test_Amazon.rb:9: warning: previous definition of PAGE_URL was here
代码如下:
require 'rubygems'
require 'nokogiri'
require 'open-uri'
for $i in (1..5)
PAGE_URL = "http://www.amazon.com/Best-Sellers/zgbs/automotive/?pg=#$i"
page = Nokogiri::HTML(open(PAGE_URL))
page.css(".zg_itemWrapper").each do |item|
price = item.at_css(".zg_price .price").text
asin = item.at_css(".zg_title a")[:href].split("/")[5].chomp
product_name = item.at_css(".zg_title a")[:href].split("/")[3]
puts "#{asin} #{price} #{product_name}"
end
end
【问题讨论】: