我正在尝试从www.thetipsterleague.com抓取数据,并且我在Postman中发出了工作后的请求,该请求获取了第n页数据,但是我的代码和Postman所说的代码都会返回以下错误我一直无法解决:
requests.exceptions.ConnectionError: ('Connection aborted.', RemoteDisconnected('Remote end closed connection without response',))
我的代码:
import requests
url = "https://www.thetipsterleague.com/ajax/tipster-tips"
params = {
"_token":"xNsJwhPG8zm5XryZPRPfXSjWfS3DE2R563TB3737",
"id":"85",
"page":"4"
}
headers = {
"Host": "www.thetipsterleague.com",
"User-Agent": "Mozilla/5.0 (X11; Ubuntu; Linux x86_64; rv:62.0) Gecko/20100101 Firefox/62.0",
"Accept": "*/*",
"Accept-Language": "en-GB,en;q=0.5",
"Accept-Encoding": "gzip, deflate, br",
"Referer": "https://www.thetipsterleague.com/tipster/hugh-taylor",
"Content-Type": "application/x-www-form-urlencoded; charset=UTF-8",
"X-Requested-With": "XMLHttpRequest",
"Content-Length": "60",
"Cookie": r"_omappvp=c12MNO2hmCaipvfx8m143s2yvPQixQVYOgLVUpkOLA1rySNAYeCUqsVc5oHnOwOxsxsOMYre5XsnlfKS0Rc6qXXRCRFEc7kn; _drip_client_8304301=vid%253D01c281f0b0f90136c7dd12348dd749b6%2526pageViews%253D16%2526sessionPageCount%253D1%2526lastVisitedAt%253D1539511134903%2526weeklySessionCount%253D3%2526lastSessionAt%253D1539511134903; _ga=GA1.2.1744392981.1539423228; _gid=GA1.2.1903882760.1539423228; om-n9lcrkxxzjauwgdzivkh=1539423673834; XSRF-TOKEN=eyJpdiI6InB3RjN0MDl6cTY1MTlsaE9md29qTkE9PSIsInZhbHVlIjoiT2MzZ3p5NHJndGozd21sdEJxaTM1RWpUN1cxTDNsUm4wRGhYZ0VzMFBQVWhuXC9xT09NK1g4Sm1EQU1HeEtWYWhJQytqV1BtaUU5TDRSTGhNUjdCSnF3PT0iLCJtYWMiOiJmOGY1ZmY5YTlkNjM0YzgyNWE3ZWNhNDljZTM0MTM4NTY1MDBmNTJjMGY1MGI0NDQ5NTM5MDg0MTE1MTk5NzIwIn0%3D; laravel_session=eyJpdiI6InhSakR3SWNHajdyTkYwa2hTcURzY3c9PSIsInZhbHVlIjoiNzVpN2Jlb0xpMXc1S21SQ3U0cjk3OGNzVTU1b0h6R0hET21PU0VYalZQdDBGQ2lnOU84MlNGV0Ftczd0ZGNPclNlTzFSRDJPN0hYWVJveFF0YThZeWc9PSIsIm1hYyI6IjViNWM5MDZjYTVmMDFhMDMzOTI5NTYxYjczNTliMDI2Mzg3YjA0MWY5OWM3NmZjZWIzYTAxODAwNzU4ZTY4ZTQifQ%3D%3D; _gat_gtag_UA_115644339_1=1; _hjIncludedInSample=1",
"Connection": "keep-alive",
"TE": "Trailers"
}
r = requests.post(url, headers = headers, params = params)
print(r.text)
邮递员的代码:
import requests
url = "https://www.thetipsterleague.com/ajax/tipster-tips"
querystring = {"_token":"xNsJwhPG8zm5XryZPRPfXSjWfS3DE2R563TB3737","id":"85","page":"4"}
headers = {
'Host': "www.thetipsterleague.com",
'User-Agent': "Mozilla/5.0 (X11; Ubuntu; Linux x86_64; rv:62.0) Gecko/20100101 Firefox/62.0",
'Accept': "*/*",
'Accept-Language': "en-GB,en;q=0.5",
'Accept-Encoding': "gzip, deflate, br",
'Referer': "https://www.thetipsterleague.com/tipster/hugh-taylor",
'Content-Type': "application/x-www-form-urlencoded; charset=UTF-8",
'X-Requested-With': "XMLHttpRequest",
'Content-Length': "60",
'Cookie': "_omappvp=c12MNO2hmCaipvfx8m143s2yvPQixQVYOgLVUpkOLA1rySNAYeCUqsVc5oHnOwOxsxsOMYre5XsnlfKS0Rc6qXXRCRFEc7kn; _drip_client_8304301=vid%253D01c281f0b0f90136c7dd12348dd749b6%2526pageViews%253D16%2526sessionPageCount%253D1%2526lastVisitedAt%253D1539511134903%2526weeklySessionCount%253D3%2526lastSessionAt%253D1539511134903; _ga=GA1.2.1744392981.1539423228; _gid=GA1.2.1903882760.1539423228; om-n9lcrkxxzjauwgdzivkh=1539423673834; XSRF-TOKEN=eyJpdiI6InB3RjN0MDl6cTY1MTlsaE9md29qTkE9PSIsInZhbHVlIjoiT2MzZ3p5NHJndGozd21sdEJxaTM1RWpUN1cxTDNsUm4wRGhYZ0VzMFBQVWhuXC9xT09NK1g4Sm1EQU1HeEtWYWhJQytqV1BtaUU5TDRSTGhNUjdCSnF3PT0iLCJtYWMiOiJmOGY1ZmY5YTlkNjM0YzgyNWE3ZWNhNDljZTM0MTM4NTY1MDBmNTJjMGY1MGI0NDQ5NTM5MDg0MTE1MTk5NzIwIn0%3D; laravel_session=eyJpdiI6InhSakR3SWNHajdyTkYwa2hTcURzY3c9PSIsInZhbHVlIjoiNzVpN2Jlb0xpMXc1S21SQ3U0cjk3OGNzVTU1b0h6R0hET21PU0VYalZQdDBGQ2lnOU84MlNGV0Ftczd0ZGNPclNlTzFSRDJPN0hYWVJveFF0YThZeWc9PSIsIm1hYyI6IjViNWM5MDZjYTVmMDFhMDMzOTI5NTYxYjczNTliMDI2Mzg3YjA0MWY5OWM3NmZjZWIzYTAxODAwNzU4ZTY4ZTQifQ%3D%3D; _gat_gtag_UA_115644339_1=1; _hjIncludedInSample=1",
'Connection': "keep-alive",
'TE': "Trailers",
'Cache-Control': "no-cache",
'Postman-Token': "0652cfcc-a36f-4fc0-8b8f-5b0600ab021c"
}
response = requests.request("POST", url, headers=headers, params=querystring)
print(response.text)
我的头文件只是从Firefox控制台复制的。
编辑:_token
经常更改。