[英]scraping yell with python requests gives 403 error
我有這個代碼
from requests.sessions import Session
url = "https://www.yell.com/s/launderettes-birmingham.html"
s = Session()
headers = {
'user-agent':"Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/100.0.4896.127 Safari/537.36",
}
r = s.get(url,headers=headers)
print(r.status_code)
但我得到 403 輸出,而不是 200
我可以用 selenium 刮取這些數據,但是有沒有辦法用請求刮取這些數據
如果您像這樣修改代碼:
print(r.text)
print(r.status_code)
您會看到,您收到 400 錯誤代碼的原因是由於使用 Cloudflare 瀏覽器檢查而yell
。
由於它使用 javascript,因此無法可靠地使用 requests 模塊。
既然您提到您將使用 selenium,請確保使用未檢測到的驅動程序包另外,請確保輪換您的 IP以避免您的 IP 被阻止。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.