1
>>require 'net/https'
>>uri = URI('https://www.facebook.com/careers/department?dept=product-management&req=a2KA0000000E147MAC')
>>conn = Net::HTTP.new(uri.host, uri.port)
>>req = Net::HTTP::Get.new(uri.request_uri, {'User Agent' => 'Mozilla/5.0 (Macintosh; Intel Mac OS X 10_6_8) AppleWebKit/537.1 (KHTML, like Gecko) Chrome/21.0.1180.89 Safari/537.1'})
>>resp = conn.request req
=> #<Net::HTTPFound 302 Found readbody=true>

网站抛出的 302 重定向重定向到“不支持的浏览器”页面。我在为此请求设置用户代理时做错了什么?我正在使用浏览器返回的相同用户代理字符串。附加信息:在这个用例中,我不能使用诸如 watir 之类的库。任何使用“net/http[s]”或“open-uri”的解决方案都很棒。

4

1 回答 1

3

使用连字符将“用户代理”更改为“用户代理”。

于 2012-09-02T20:59:56.993 回答