我已经尝试了其他类似的方法,但没有任何效果,有时效果很好,但是它给了我这个错误,我已经设置了User-Agent,并且正在使用请求会话,
import requests
requestHeaders = {
'User-Agent': 'Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/84.0.4147.89 Safari/537.36',
'Accept': 'text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,*/*;q=0.8',
'Accept-Language': 'en-US,en;q=0.5',
'Accept-Encoding': 'gzip, deflate, br',
'Referer': 'https://www.dell.com/support/home/en-us?app=warranty',
'Connection': 'keep-alive',
'Upgrade-Insecure-Requests': '1',
'TE': 'Trailers',
'Content-Type': 'text/plain'
}
session = requests.Session()
a = session.get("url", headers=requestHeaders)
print(a.status_code)
此代码返回403访问被拒绝,我们将不胜感激。
答案 0 :(得分:1)
问题出在您的标题上。使用这些,我可以获得一个200
状态码。
headers = {
"User-Agent": "Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/56.0.2924.76 Safari/537.36",
"Upgrade-Insecure-Requests": "1",
"DNT": "1",
"Accept": "text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8",
"Accept-Language": "en-US,en;q=0.5",
"Accept-Encoding": "gzip, deflate",
}