SSL证书
Cookie
import requests
# url ='https://inv-veri.chinatax.gov.cn'
headers=headers = {
'user-agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/88.0.4324.104 Safari/537.36'}
# res =requests.get(url,headers=headers,verify=False)
# print(res.text)
url ='http://www.renren.com/974676254/profile'# 个人主界面
res =requests.get(url,headers=headers) #获取响应对象
# html = res.text
with open('rr.html','w',encoding='utf-8')as f:
f.write(res.text)
## 添加cookie就可以
import requests
# url ='https://inv-veri.chinatax.gov.cn'
headers=headers = {
'user-agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/88.0.4324.104 Safari/537.36','Cookie':'anonymid=knuah4rlg19q8v; depovince=GUZ; jebecookies=9fa66178-66e2-4a23-b530-4e9c627e6273|||||; _r01_=1; JSESSIONID=abcLTfJ0P4Oov_4lYS_Jx; ick_login=7ca72789-831c-4f66-a502-c49190fe2c46; taihe_bi_sdk_uid=68327472d5a51ad2df417dfe0cdc315f; taihe_bi_sdk_session=4fc61b70afef852aca6587d8a70ef277'}
# res =requests.get(url,headers=headers,verify=False)
# print(res.text)
url ='http://www.renren.com/974676254/profile'# 个人主界面
res =requests.get(url,headers=headers) #获取响应对象
# html = res.text
with open('rr.html','w',encoding='utf-8')as f:
f.write(res.text)
cookie–反反爬
网页看到数据,源代码没有——ajax
解决
数据找到了:
被反爬了
def query():
headers = {
'user-agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/88.0.4324.104 Safari/537.36'}
res =requests.get('https://kyfw.12306.cn/otn/leftTicket/query?leftTicketDTO.train_date=2021-04-26&leftTicketDTO.from_station=CSQ&leftTicketDTO.to_station=BJP&purpose_codes=ADULT',headers=headers)
print(res.content.decode('utf-8'))
query()
解决——加cookie
找到了车次[3]和有无票[23]
def query()