0

我有一个简单的 ruby​​ 文件,可以从沃尔玛的网站上取消价格。我做了一个 gem install scrapi 和一个 gem install tidy。当我在 Windows 7 机器上运行代码时,出现以下错误:

错误

c:/Ruby193/lib/ruby/gems/1.9.1/gems/scrapi-2.0.0/lib/scraper/reader.rb:216:in `r escue in parse_page': Scraper::Reader::HTMLParseError: didn't find tidy libs on your system. Please install tidy (http://tidy.sourceforge.net/) (Scraper::Reader ::HTMLParseError)

它似乎找不到整洁的库,所以我把它放在我的路径中:

路径=C:\Ruby193\lib\ruby\gems\1.9.1\gems\tidy_ffi-0.1.5\lib;C:\Ruby193\lib\ruby\gems\1.9.1\gems\tidy-1.1.2\库

但它仍然抛出同样的找不到整洁的库错误。

在此先感谢您的帮助。

代码

require 'rubygems'
require 'scrapi'
require 'tidy'

scraper = Scraper.define do
process "div.firstRow div.priceAvail>div>div.PriceCompare>div.BodyS", :price => :text
result :price
end

url = URI.parse("http://www.walmart.com/search/search-ng.do?search_constraint=0&ic=48_0&search_query=LOST+third+season&Find.x=17&Find.y=1&Find=Find")
puts scraper.scrape(url)
4

2 回答 2

0

我有完全相同的问题,但在 Linux 上。

这与 reader.rb 中的 find_tidy 函数有关 - 不知何故,它无法找到库。我刚刚去评论了那条线,现在它工作正常。

      # Make sure the Tidy path is set and always apply the default
      # options (these only control things like errors, output type).
      # find_tidy
      options = (options || {}).update(TIDY_OPTIONS)

如果您确定系统中有整洁的库,请尝试一下。

于 2013-01-29T20:43:03.650 回答
0

我在mac上遇到了同样的问题。

攻击性代码位于 reader.rb 文件的第 204 行。在您喜欢的编辑器中打开它:

atom /usr/local/lib/ruby/gems/2.2.0/gems/scrapi-2.0.0/lib/scraper/reader.rb

就像前面的答案说的那样把它注释掉。之后效果很好。

于 2015-07-31T11:03:10.117 回答