开发者

OpenURI::HTTPError: 403 Forbidden

开发者 https://www.devze.com 2022-12-21 06:21 出处:网络
i\'m using wikipedia-api plugin for get content\'s pages from wikipedia. From some days i receive this error when i try to get the contents:

i'm using wikipedia-api plugin for get content's pages from wikipedia. From some days i receive this error when i try to get the contents:

  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'

What is that?

How can i do?

thanks


I've solved changing

Hpricot.XML(open(url))

in

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

In the mediawiki.rb file


Yes it works.

The same for Nokogiri 403 Forbidden problems

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

0

精彩评论

暂无评论...
验证码 换一张
取 消