2015-09-30 53 views
-2

檢查下面的代碼,我認爲有什麼問題的cookie,因爲當我通過瀏覽器的cookie它的作品。該網站沒有出現在python請求

import requests 

header = { 
      'Accept':'text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,*/*;q=0.8', 
      'Accept-Encoding':'gzip, deflate, sdch', 
      'Accept-Language':'en-US,en;q=0.8', 
      'Cache-Control':'max-age=0', 
      'Connection':'keep-alive', 
      'Host':'secure.in.gov', 
      'content-length':'6917', 
      'Upgrade-Insecure-Requests':'1', 
      'user-agent':'Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/45.0.2454.101 Safari/537.36', 
      } 

with requests.Session() as session: 

    session.get("https://secure.in.gov/sos/online_corps/name_search.aspx",headers=header,verify=True) 

    session.cookies['__utma'] = '58136434.1826530329.1443539661.1443539661.1443539661.1' 
    session.cookies['__utmc'] = '58136434' 
    session.cookies['__utmz'] = "58136434.1443539661.1.1.utmcsr=(direct)|utmccn=(direct)|utmcmd=(none)" 
    session.cookies['_ga'] = 'GA1.2.1826530329.1443539661' 
    session.cookies['__qca'] = 'P0-2058828605-1443539662643' 
    session.cookies['_baga'] = 'GA1.2.1826530329.1443539661' 

    session.get("https://secure.in.gov/sos/online_corps/name_search_results.aspx?search_name=AA&search_type=exact&client_id=&submit.x=23&submit.y=6&submit=submit&search_mode=search",headers=header,verify=True) 

    reponse = session.get("https://secure.in.gov/sos/online_corps/view_details.aspx?guid=E5D19DA1-9E31-4758-9656-5BC54F43F972",headers=header,verify=True) 

    print(reponse.content) 

回答

0

我認爲這個網站的cookie正在改變。所以你應該使用CookieJar來處理cookie。

+0

我用requests.Session()來處理cookie,我也嘗試了CookieJar,但不起作用。 –