我正试着向皮卡比发出请求。
这是我的密码
import requests
url = 'https://pixabay.com'
header = {
'User-Agent': 'Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_3) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/80.0.3987.100 Safari/537.36'
}
req = requests.get(url, headers=header)
print(req.status_code)
print(req.headers)
print(req.text)它不能工作(403错误)。我怎样才能工作?
发布于 2020-02-12 09:16:40
Pixabay具有Cloudflare安全性,如果从黑名单上的IP连接,则需要解决captcha问题。
为了绕过这一点,您必须首先通过浏览器进行连接,然后将头和cookie复制到python脚本中。这是为我工作,但你必须更换的部分,如__cfduid,这是您的云彩指纹,以访问该网站。还要检查您的用户代理是否正确。
import requests
url = 'https://pixabay.com/'
header = {
'User-Agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/77.0.3835.0 Safari/537.36',
'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',
'Upgrade-Insecure-Requests': '1',
'Host': 'pixabay.com'
}
cookie = {
'__cfduid': '<redacted>',
'cf_clearance': '<redacted>',
'anonymous_user_id': '<redacted>',
'_sp_ses.aded': '*',
'_sp_id.aded': '<redacted>',
'is_human': '1',
'client_width':'1540'
}
req = requests.get(url, headers=header, cookies=cookie)
print(req.status_code)
print(req.headers)https://stackoverflow.com/questions/60184675
复制相似问题