2013-08-28 42 views
0

我試圖抓取一個網站,但每次我需要通過firebug從request_headers cookie獲取phpsessid,否則它將返回500,我試圖使用SecureRandom.hex(13)生成phpsessid,但它贏得了' t工作,解決這個問題的任何解決方案?使用機械化處理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]}" 
        }) 

回答