使用机械化处理phpsessid

时间:2013-08-28 10:11:57

标签: ruby-on-rails ruby mechanize

我试图抓取一个网站,但每次我需要通过firebug从request_headers cookie获取phpsessid或者它将返回500,我尝试使用SecureRandom.hex(13)生成一个phpsessid但是它不起作用,任何解决方案解决这个问题?

   a = Mechanize.new
    a.request_headers = {
          "Accept" => "text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8",
          "Content-type" => "application/x-www-form-urlencoded; charset=UTF-8",
          "host" => "www.website.com",
          "Referer" => "http://www.website.com/equipment",
          "Accept-Encoding" => "gzip, deflate",
          "X-Requested-With" => "XMLHttpRequest",
          "Pragma" => "no-cache",
          "Cookie" => "__alti_visits=1; __PAPVisitorId=#{SecureRandom.hex(16)}; __alti_visits=2; PHPSESSID=#{SecureRandom.hex(13)}; skimiuml=2; __altima_newvisit_detect=1;" 
           }


    a.post("http://www.website.com/action", 
                 {
                   "display" => "desktop",
                   "category" => "#{product_type_id[c]}",
                   "target" => "#{product_genre_id[a1]}"
                  })

1 个答案:

答案 0 :(得分:0)

类似的问题是Maintaining cookies between Mechanize requests。你试过吗?