声明:
该文章为学习使用,严禁用于商业用途和非法用途,违者后果自负,由此产生的一切后果均与作者无关
import requests
import re
headers = {
"Accept": "application/json, text/plain, */*",
"Accept-Language": "zh-CN,zh;q=0.9",
"Cache-Control": "no-cache",
"Content-Type": "application/x-www-form-urlencoded",
"Origin": "http://www.zjmazhang.gov.cn",
"Pragma": "no-cache",
"Proxy-Connection": "keep-alive",
"Referer": "http://www.zjmazhang.gov.cn/",
"User-Agent": "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/119.0.0.0 Safari/537.36",
# "X-CSRF-TOKEN": "RxuDLCESEXCWLi8iOKojqI77MVyigEqC2MXgfV7e"
}
cookies = {
"zh_choose": "n",
# "XSRF-TOKEN": "eyJpdiI6Ilc0RlV1cFQrdVIzNk1xTlJEajM2RFE9PSIsInZhbHVlIjoiZ216VHB6Y3paUUJqSCtERzlsS0w4clZZY2RQWUcyRGRNOFRPU1hKaGtBVUlmd1I3VjB1Zkh2YkRLamdEWGZMSCIsIm1hYyI6ImU3MjQ1YjYyNDRhM2MwYWQxZGFmODYxODk4MzY4YzE0OTM0NjViMTI5NDRiYjI1YzNjNDRhNzU4NjU4NjJiM2EifQ%3D%3D",
# "szxx_session": "eyJpdiI6IkVER0lEV1FlM0NwTE5YWFpKbExnNWc9PSIsInZhbHVlIjoiVG5zQ3oxa3NMVm1Ra0d5Z1Q4akJ3aXlVbm1LNG9lMUFSTmM2d3hPdkE3REhNTE5tU2xTd2FUYzZvSUtCQTFDUiIsIm1hYyI6ImVlY2VjNmY1MjJhMDQ3OWM0OTJiZmEyMmVjZmYxOTExZDY1NDg1Y2VhMmRhZWM1OTE5YTZlNjI3ZTQzMzc4MDIifQ%3D%3D"
}
request_session = requests.session()
request_session.headers.update(headers)
request_session.cookies.update(cookies)
def get_cookie():
cookie_request = request_session.get('http://www.zjmazhang.gov.cn/hdjlpt/published?via=pc')
cookies['XSRF-TOKEN'] = cookie_request.cookies['XSRF-TOKEN']
cookies['szxx_session'] = cookie_request.cookies['szxx_session']
request_session.cookies.update(cookies)
html = cookie_request.text
headers['X-CSRF-TOKEN'] = re.findall("var _CSRF = '(.*?)';",html)[0]
request_session.headers.update(headers)
get_cookie()
url = "http://www.zjmazhang.gov.cn/hdjlpt/letter/pubList"
data = {
"offset": "0",
"limit": "20",
"site_id": "759010",
"time_from": "1669737600",
"time_to": "1701273599"
}
response = requests.post(url, headers=headers, cookies=cookies, data=data, verify=False)
print(response.text)
print(response)