[問題] net/http 的 bug?

作者: ireullin (raison detre)   2015-04-21 14:21:50
我正在爬取一些資料
執行了下面程式碼之後
rsp.code 為301 redirect
照理說Location的欄位應該是 (我使用fiddler觀察的)
http://www.amazon.com/Ravelli-ATD-Professional-Tripod-Camera/dp/B000YB862E/ref=redir_mobile_desktop?ie=UTF8&keywords=Camera%2C%20Photo%20%26%20Video&pi=AC_SX110_SY165_QL70&qid=1429517964&ref_=mp_s_a_1_1&sr=8-1
但我取出來之後還是原本的
http://www.amazon.com/gp/aw/d/B000YB862E/ref=mp_s_a_1_1?qid=1429517964&sr=8-1&pi=AC_SX110_SY165_QL70&keywords=Camera%2C+Photo+%26+Video
這樣我沒辦法進行redirect的動作 冏rz
是我弄錯了嗎
還是真的有bug
是否有人遇到相同問題?
程式碼如下
uri =
'http://www.amazon.com/gp/aw/d/B000YB862E/ref=mp_s_a_1_1?qid=1429517964&sr=8-1&pi=AC_SX110_SY165_QL70&keywords=Camera%2C+Photo+%26+Video'
req = Net::HTTP::Get.new(URI(uri))
rsp = Net::HTTP.start(uri.hostname, uri.port) {|http| http.request(req) }
puts rsp.code
puts rsp.header['Location']
puts rsp.header.to_hash.to_json
以下是我使用的版本
$ ruby
作者: ireullin (raison detre)   2015-04-21 17:49:00
自己解決了,需要在header中另外在塞入cookie才會回覆正確的資訊,麻煩大家了,謝謝

Links booklink

Contact Us: admin [ a t ] ucptt.com