5

我正在使用 wikipedia-api 插件从维基百科获取内容页面。从某些日子开始,当我尝试获取内容时收到此错误:

  page = Wikipedia.find_by_titles('Foo')
OpenURI::HTTPError: 403 Forbidden
    from /usr/lib/ruby/1.8/open-uri.rb:277:in `open_http'
    from /usr/lib/ruby/1.8/open-uri.rb:616:in `buffer_open'
    from /usr/lib/ruby/1.8/open-uri.rb:164:in `open_loop'
    from /usr/lib/ruby/1.8/open-uri.rb:162:in `catch'
    from /usr/lib/ruby/1.8/open-uri.rb:162:in `open_loop'
    from /usr/lib/ruby/1.8/open-uri.rb:132:in `open_uri'
    from /usr/lib/ruby/1.8/open-uri.rb:518:in `open'
    from /usr/lib/ruby/1.8/open-uri.rb:30:in `open'
    from /home/luca/Programming/nerto_5/vendor/plugins/wikipedia-api/lib/mediawiki.rb:139:in `get_xml'

那是什么?

我能怎么做?

谢谢

4

2 回答 2

6

我已经解决了改变

Hpricot.XML(open(url))

  Hpricot.XML(open(url, 'User-Agent' => 'ruby'))

在 mediawiki.rb 文件中

于 2010-02-22T13:39:49.400 回答
3

是的,它有效。

Nokogiri 403 Forbidden 问题也是如此

doc = Nokogiri::HTML(open(site, 'User-Agent' => 'ruby'))

于 2010-09-04T21:00:08.420 回答