检查下面的代码,我认为cookie有问题,因为当我通过浏览器的cookie时,它会起作用。
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 :(得分:0)
我认为这个网站的cookie正在改变。所以你应该使用CookieJar来处理cookie。