python requests headers cookiesログイン方法の1つ
3401 ワード
import requests
s=requests.session()
url="https://www.tianyancha.com/search?key= "
headers={
"Accept":"text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,image/apng,*/*;q=0.8",
"Accept-Encoding":"gzip, deflate, br",
"Accept-Language":"zh-CN,zh;q=0.9,en;q=0.8",
"Connection":"keep-alive",
"Cookie":"TYCID=95527c1610397911e8bff6ed77ba820561; undefined=527c1610397911e8bff6ed77ba820561; ssuid=1836004500; _ga=GA1.2.1102138489.1531815381; _gid=GA1.2.439505005.1543210985; tyc-user-info=%257B%2522myQuestionCount%2522%253A%25220%2522%252C%2522integrity%2522%253A%25220%2525%2522%252C%2522state%2522%253A%25220%2522%252C%2522vipManager%2522%253A%25220%2522%252C%2522onum%2522%253A%25220%2522%252C%2522monitorUnreadCount%2522%253A%252231%2522%252C%2522discussCommendCount%2522%253A%25221%2522%252C%2522token%2522%253A%2522eyJhbGciOiJIUzUxMiJ9.eyJzdWIiOiIxMzcyNTUwNTc2OCIsImlhdCI6MTU0MzMwODIwMiwiZXhwIjoxNTU4ODYwMjAyfQ.Lv41AYfYcieyjXObqukIfhuzFDa_H2Vb3Xuh7MqHDn9wHKpQG87X02yRJ2LB3MS2R-vr5Yn2AogHvnwHxHtxPQ%2522%252C%2522redPoint%2522%253A%25220%2522%252C%2522pleaseAnswerCount%2522%253A%25221%2522%252C%2522vnum%2522%253A%25220%2522%252C%2522bizCardUnread%2522%253A%25220%2522%252C%2522mobile%2522%253A%252213725505768%2522%257D; auth_token=eyJhbGciOiJIUzUxMiJ9.eyJzdWIiOiIxMzcyNTUwNTc2OCIsImlhdCI6MTU0MzMwODIwMiwiZXhwIjoxNTU4ODYwMjAyfQ.Lv41AYfYcieyjXObqukIfhuzFDa_H2Vb3Xuh7MqHDn9wHKpQG87X02yRJ2LB3MS2R-vr5Yn2AogHvnwHxHtxPQ; RTYCID=51b3ced1f28d4882a3978233b80680d3; CT_TYCID=a3fc8e61319e4802a17aa906f3b3b0da; aliyungf_tc=AQAAAEvHyG+iwwAA+Olw3P3xcz7pHmCO; csrfToken=OZverume68dXtF1ctYCNRzO5; Hm_lvt_e92c8d65d92d534b0fc290df538b4758=1543310105,1543385226,1543390158,1543398990; Hm_lpvt_e92c8d65d92d534b0fc290df538b4758=1543399314",
"Host":"www.tianyancha.com",
"Upgrade-Insecure-Requests":"1",
"User-Agent":"Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/70.0.3538.110 Safari/537.36"
}
cookies={
"CT_TYCID":"a3fc8e61319e4802a17aa906f3b3b0da",
"Hm_lpvt_e92c8d65d92d534b0fc290df538b4758":"1543399314",
"Hm_lvt_e92c8d65d92d534b0fc290df538b4758":"1543310105,1543385226,1543390158,1543398990",
"RTYCID":"51b3ced1f28d4882a3978233b80680d3",
"TYCID":"95527c1610397911e8bff6ed77ba820561",
"_ga":"GA1.2.1102138489.1531815381",
"_gid":"GA1.2.439505005.1543210985",
"aliyungf_tc":"AQAAAEvHyG+iwwAA+Olw3P3xcz7pHmCO",
"auth_token":"eyJhbGciOiJIUzUxMiJ9.eyJzdWIiOiIxMzcyNTUwNTc2OCIsImlhdCI6MTU0MzMwODIwMiwiZXhwIjoxNTU4ODYwMjAyfQ.Lv41AYfYcieyjXObqukIfhuzFDa_H2Vb3Xu",
"csrfToken":"OZverume68dXtF1ctYCNRzO5",
"ssuid":"1836004500",
"tyc-user-info":"%257B%2522myQuestionCount%2522%253A%25220%2522%252C%2522integrity%2522%253A%25220%2525%2522%252C%2522state%2522%253A%2522",
"undefined":"527c1610397911e8bff6ed77ba820561"
}
rs=s.get(url,headers=headers,cookies=cookies,verify=False)
rs.encoding='utf-8'
print(rs.text)
f=open("cookiesTest.html","w",encoding='utf-8')
f.write(rs.text)
f.close()
print("-------------ok-------------")