google headers格式转换
def googleHeadersFormat(headers):
'''
google headers格式转换
:param headers:
:return:header_dict
'''
header_dict = {}
for header in headers.split('\n'):
header_dict[header.split(':')[0]] = header[len(header.split(':')[0]) + 1:].strip()
return header_dict
firefox headers格式转换
def huohuHeaderFormat(headers):
'''
火狐header格式转换
:param headers:
:return:header_dict
'''
header_dict={}
for key in headers.keys():
for header_info in headers[key]['headers']:
header_dict[header_info['name']]=header_info['value']
return header_dict
判断服务器检测哪些headers头
class TestHeaders:
def get(self, url, headers):
"""
检测headers中有用的头部信息
:param url:
:param headers:
:return:
"""
res1 = requests.get(url=url, headers=headers)
for key in list(headers.keys()):
headers2 = copy.deepcopy(headers)
del headers2[key]
res = requests.get(url=url, headers=headers2)
if len(res1.text) != len(res.text):
print('检测headers头:{} '.format(key))
def post(self,url, headers, data):
"""
检测headers中有用的头部信息
:param url:
:param headers:
:param data:
:return:
"""
res1 = requests.post(url=url, headers=headers, data=data)
for key in list(headers.keys()):
headers2 = copy.deepcopy(headers)
del headers2[key]
res = requests.post(url=url, headers=headers2, data=data)
if len(res1.text) !=len(res.text):
print('检测headers头:{} '.format(key))
判断服务器检测哪些cookies值
class TestCookies:
def get(self,url, headers, cookie_dict):
"""
检测cookies中有用的值
:param url:
:param headers:
:param cookies: Cookie: BAIDUID=933818930EC617BA9DBD9A5A6824C065:FG=1; BIDUPSID=933818930EC617BA91FB2AAD99D2532A; PSTM=1633267654; __yjs_duid=1_b02549f02976c756f53dc2628aef7ccf1633267669753; Hm_lvt_64ecd82404c51e03dc91cb9e8c025574=1637223401,1637415773,1637467427,1637476253; REALTIME_TRANS_SWITCH=1; FANYI_WORD_SWITCH=1; HISTORY_SWITCH=1; SOUND_SPD_SWITCH=1; SOUND_PREFER_SWITCH=1; BDUSS=llaNWhTbHJON3J5ZUI3ZXI3Q1hzcFg5Z0ZqNmRHMFBreWZaSndUaldpa1p3cFJoSVFBQUFBJCQAAAAAAQAAAAEAAABEQ-VPaGFwcHn2zrTvtO8AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAABk1bWEZNW1hS; __yjs_st=2_YzkyZDlhNzM2MDA4MzMyYjA0MzZhMmVlNzA4NzU0MTdlYTZiNzg4ZTg4OGZhNmJmOTE1OWViODhmZTU4YWJjYzE4MmMyZDZjMmVjNzc1OTdhMTZmZjAzOThmYmYyMDY4YmU5ZWVmZDcwMWY3ZDc5ZmI3NDFmZDdhMThjYzhmNDYwZjFjOWM0NmQ2YTdkNGJhMTA2ODI5YTJhZDNmYTVmODMyMTljNzI1NzBlYjJmMzRkOGVmYmZhZTI2ZTgxZDAwMWRjZDQzZjlmMGVkMjViZDAxOWI2YmI1OGUxOTI3ZWM4OTQyYjk1OGZlZDZlZWNjMGEwNjAyNjY5MTc4ZTRhNl83XzcxMmI4NWY4; BDORZ=FFFB88E999055A3F8A630C64834BD6D0; ab_sr=1.0.1_YzdlNmU4ZTY5ODNlNTA4OTc1MTU4YmJiMDA0NWM2NjNiMTg2YTc4MGFjODhiMTRkYWY2YTBhZTMzM2UyZDUxZWVkMjYyNjEzOGUwNDZkYTEwODE1ZjUxNDM4ODMwMzJlOTM2NDk3ZGMzMzhkMmEzM2JjMTRmM2M3MDMyNGYzZDYxZmFjN2UzODQwMzA3MWNkOTIyZjIxNjAzMDIwNGJkMg==; BDRCVFR[9M3uyrD9jZb]=dhaJUOdr3F0mh-bpy78ugc8mvqV; delPer=0; PSINO=6; H_PS_PSSID=26350; BA_HECTOR=2h2g240h252ka4a17r1gpjpss0q; Hm_lpvt_64ecd82404c51e03dc91cb9e8c025574=1637476266
:return:
"""
print(cookie_dict)
res1 = requests.get(url=url, headers=headers, cookies=cookie_dict)
for key in list(cookie_dict.keys()):
cookie_dict1 = copy.deepcopy(cookie_dict)
del cookie_dict1[key]
res = requests.get(url=url, headers=headers, cookies=cookie_dict1)
if len(res1.text) != len(res.text):
print('检测cookies键:{}'.format(key))
def post(self,url,headers,data,cookie_dict):
"""
检测cookies中有用的值
:param url:
:param headers:
:param data:
:param cookies: Cookie: BAIDUID=933818930EC617BA9DBD9A5A6824C065:FG=1; BIDUPSID=933818930EC617BA91FB2AAD99D2532A; PSTM=1633267654; __yjs_duid=1_b02549f02976c756f53dc2628aef7ccf1633267669753; Hm_lvt_64ecd82404c51e03dc91cb9e8c025574=1637223401,1637415773,1637467427,1637476253; REALTIME_TRANS_SWITCH=1; FANYI_WORD_SWITCH=1; HISTORY_SWITCH=1; SOUND_SPD_SWITCH=1; SOUND_PREFER_SWITCH=1; BDUSS=llaNWhTbHJON3J5ZUI3ZXI3Q1hzcFg5Z0ZqNmRHMFBreWZaSndUaldpa1p3cFJoSVFBQUFBJCQAAAAAAQAAAAEAAABEQ-VPaGFwcHn2zrTvtO8AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAABk1bWEZNW1hS; __yjs_st=2_YzkyZDlhNzM2MDA4MzMyYjA0MzZhMmVlNzA4NzU0MTdlYTZiNzg4ZTg4OGZhNmJmOTE1OWViODhmZTU4YWJjYzE4MmMyZDZjMmVjNzc1OTdhMTZmZjAzOThmYmYyMDY4YmU5ZWVmZDcwMWY3ZDc5ZmI3NDFmZDdhMThjYzhmNDYwZjFjOWM0NmQ2YTdkNGJhMTA2ODI5YTJhZDNmYTVmODMyMTljNzI1NzBlYjJmMzRkOGVmYmZhZTI2ZTgxZDAwMWRjZDQzZjlmMGVkMjViZDAxOWI2YmI1OGUxOTI3ZWM4OTQyYjk1OGZlZDZlZWNjMGEwNjAyNjY5MTc4ZTRhNl83XzcxMmI4NWY4; BDORZ=FFFB88E999055A3F8A630C64834BD6D0; ab_sr=1.0.1_YzdlNmU4ZTY5ODNlNTA4OTc1MTU4YmJiMDA0NWM2NjNiMTg2YTc4MGFjODhiMTRkYWY2YTBhZTMzM2UyZDUxZWVkMjYyNjEzOGUwNDZkYTEwODE1ZjUxNDM4ODMwMzJlOTM2NDk3ZGMzMzhkMmEzM2JjMTRmM2M3MDMyNGYzZDYxZmFjN2UzODQwMzA3MWNkOTIyZjIxNjAzMDIwNGJkMg==; BDRCVFR[9M3uyrD9jZb]=dhaJUOdr3F0mh-bpy78ugc8mvqV; delPer=0; PSINO=6; H_PS_PSSID=26350; BA_HECTOR=2h2g240h252ka4a17r1gpjpss0q; Hm_lpvt_64ecd82404c51e03dc91cb9e8c025574=1637476266
:return:
"""
res1 = requests.post(url=url, headers=headers, data=data, cookies=cookie_dict)
for key in list(cookie_dict.keys()):
cookie_dict1=copy.deepcopy(cookie_dict)
del cookie_dict1[key]
res = requests.post(url=url, headers=headers, data=data,cookies=cookie_dict1)
if len(res1.text) != len(res.text):
print('检测cookies键:{}'.format(key))
|