这个是用来模拟需要token的请求
time.sleep(5)
session = Session()
r = session.get('https://cplus.hit.com.hk/frontpage/#/')
xsrf = urllib.parse.unquote(r.cookies['XSRF-TOKEN'])
url = 'https://cplus.hit.com.hk/WebAPI/Pub/PubVesselSchedule'
HEADERS = {
'Accept': 'application/json, text/plain, */*',
'Accept-Encoding': 'gzip, deflate, br',
'Accept-Language': 'zh-CN,zh;q=0.9',
'Connection': 'keep-alive',
'Content-Length': '92',
'Content-Type': 'application/json',
'Host': 'cplus.hit.com.hk',
'Origin': 'https://cplus.hit.com.hk',
'Referer': 'https://cplus.hit.com.hk/frontpage/',
'sec-ch-ua': '" Not A;Brand";v="99", "Chromium";v="109", "Google Chrome";v="109"',
'sec-ch-ua-mobile': '?0',
'sec-ch-ua-platform': '"Windows"',
'Sec-Fetch-Dest': 'empty',
'Sec-Fetch-Mode': 'cors',
'Sec-Fetch-Site': 'same-origin',
'User-Agent': 'Mozilla/5.0 (Windows NT 6.1; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/99.0.4844.84 Safari/537.36',
'X-XSRF-TOKEN': xsrf
}
data = '{"companyCode":"","fromDate":"' + (datetime.datetime.now() + relativedelta(days=-13)).strftime("%d/%m/%Y") + '","toDate":"' +(datetime.datetime.now() + relativedelta(days=+13)).strftime("%d/%m/%Y") + '","vesselName":"' + crawl_task.vessel_name + '"}'
以下是正解