关于在抓取网站时获取404错误页面的问题

2024-05-13 18:48:34 发布

您现在位置:Python中文网/ 问答频道 /正文

我想从'https://alternative.me/crypto/ 我使用Chrome网络工具找到了一个XHR数据所在的url,但是当我试图刮取网站时,我得到了404或500个错误页面

url = 'https://alternative.me/api/crypto/fear-and-greed-index/history'
headers = {
    'user-agent': ('Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/90.0.4430.212 Safari/537.36'),
    'Referer': ('https://alternative.me/crypto/fear-and-greed-index/'),
    'Accept-Language': ('ko-KR,ko;q=0.9,en-US;q=0.8,en;q=0.7'),
    'accept-encoding': ('gzip, deflate, br'),
    'accept': ('application/json, text/plain, */*')
}

res = requests.post(url, headers=headers)

Tags: andhttpsurlindexchromecryptokoen