如何用Ruby运行ScrAPI?

时间:2014-04-23 14:07:45

标签: ruby-on-rails ruby gem web-scraping

我尝试使用以下代码rails运行scrapi:

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

scraper = Scraper.define do
    process "title", :page_name => :text
    result :page_name
end

uri = URI.parse("http://railscasts.com/episodes/173-screen-scraping-with-scrapi")
p scraper.scrape(uri)

但是我收到以下错误:

DL is deprecated, please use Fiddle
/usr/local/rvm/gems/ruby-2.0.0-p353/gems/tidy-1.1.2/lib/tidy/tidybuf.rb:5:in `<class:Tidybuf>': uninitialized constant DL::Importable (NameError)
        from /usr/local/rvm/gems/ruby-2.0.0-p353/gems/tidy-1.1.2/lib/tidy/tidybuf.rb:3:in `<top (required)>'
        from /usr/local/rvm/rubies/ruby-2.0.0-p353/lib/ruby/site_ruby/2.0.0/rubygems/core_ext/kernel_require.rb:55:in `require'
        from /usr/local/rvm/rubies/ruby-2.0.0-p353/lib/ruby/site_ruby/2.0.0/rubygems/core_ext/kernel_require.rb:55:in `require'
        from /usr/local/rvm/gems/ruby-2.0.0-p353/gems/tidy-1.1.2/lib/tidy.rb:25:in `<module:Tidy>'
        from /usr/local/rvm/gems/ruby-2.0.0-p353/gems/tidy-1.1.2/lib/tidy.rb:21:in `<top (required)>'
        from /usr/local/rvm/rubies/ruby-2.0.0-p353/lib/ruby/site_ruby/2.0.0/rubygems/core_ext/kernel_require.rb:135:in `require'
        from /usr/local/rvm/rubies/ruby-2.0.0-p353/lib/ruby/site_ruby/2.0.0/rubygems/core_ext/kernel_require.rb:135:in `rescue in require'
        from /usr/local/rvm/rubies/ruby-2.0.0-p353/lib/ruby/site_ruby/2.0.0/rubygems/core_ext/kernel_require.rb:144:in `require'
        from scrapitest.rb:3:in `<main>'

有人知道为什么会这样,我该怎么做才能解决它?

谢谢。

1 个答案:

答案 0 :(得分:0)

请尝试使用http://github.com/libc/tidy_ffi。似乎tidy gem不再维护了。