我的 python 代碼曾經可以作業,但是當我今天嘗試時,它不再作業了。我假設網站所有者最近禁止非瀏覽器請求。
代碼
import requests, bs4
res = requests.get('https://manga1001.com/日常-raw-free/')
res.raise_for_status()
print(res.text)
我讀到在 requests.get 方法中添加標頭可能有效,但我不知道我需要哪些標頭資訊才能使其作業。
錯誤
---------------------------------------------------------------------------
HTTPError Traceback (most recent call last)
<ipython-input-15-ed1948d83d51> in <module>
3 # res = requests.get('https://manga1001.com/日常-raw-free/', headers=headers_dic)
4 res = requests.get('https://manga1001.com/日常-raw-free/')
----> 5 res.raise_for_status()
6 print(res.text)
7
~/opt/anaconda3/lib/python3.8/site-packages/requests/models.py in raise_for_status(self)
939
940 if http_error_msg:
--> 941 raise HTTPError(http_error_msg, response=self)
942
943 def close(self):
HTTPError: 403 Client Error: Forbidden for url: https://manga1001.com/
轉載請註明出處,本文鏈接:https://www.uj5u.com/qita/371481.html
