尝试从中国网站获取响应时的状态代码 412
我的代码下面返回; wespons [412]>在Python上,但是从Chrome访问没有问题。
import requests
response = requests.get("http://dzs.customs.gov.cn/dzs/2747042/3995819/ls/3997385", # /index.html
headers={'Accept': 'text/html,application/xhtml+xml,application/xml;q=0.9,image/avif,image/webp,image/apng,*/*;q=0.8,application/signed-exchange;v=b3;q=0.9',
'Accept-Encoding': 'gzip, deflate',
'Accept-Language': 'en-US,en;q=0.9,pt-BR;q=0.8,pt;q=0.7',
'Cache-Control': 'max-age=0',
'Connection': 'keep-alive',
'Host': 'dzs.customs.gov.cn',
'Referer': 'http://dzs.customs.gov.cn/dzs/2747042/3995819/ls/',
'Upgrade-Insecure-Requests': '1',
'User-Agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/99.0.4844.84 Safari/537.36'})
print(response)
My code below returns <Response [412]> on Python, but accessing from Chrome has no problem.
import requests
response = requests.get("http://dzs.customs.gov.cn/dzs/2747042/3995819/ls/3997385", # /index.html
headers={'Accept': 'text/html,application/xhtml+xml,application/xml;q=0.9,image/avif,image/webp,image/apng,*/*;q=0.8,application/signed-exchange;v=b3;q=0.9',
'Accept-Encoding': 'gzip, deflate',
'Accept-Language': 'en-US,en;q=0.9,pt-BR;q=0.8,pt;q=0.7',
'Cache-Control': 'max-age=0',
'Connection': 'keep-alive',
'Host': 'dzs.customs.gov.cn',
'Referer': 'http://dzs.customs.gov.cn/dzs/2747042/3995819/ls/',
'Upgrade-Insecure-Requests': '1',
'User-Agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/99.0.4844.84 Safari/537.36'})
print(response)
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
使用 selenium-wire,带有未发现的Chromedriver 。
Solved using Selenium-wire with undetected chromedriver.