簡體   English   中英

Web 抓取客戶評論

[英]Web Scraping Customer Reviews

作為我工作項目的一部分,我試圖從 G2 中抓取客戶評論,但出現 403 錯誤。 關於如何 go 的任何想法?

HTTPError: HTTP 錯誤 403: Forbidden

from urllib.request import Request, urlopen

req = Request("https://www.g2.com/products/google-drive/reviews", headers={'User-Agent': 'Mozilla/5.0'})

web_byte = urlopen(req).read()

webpage = web_byte.decode('utf-8')

parsed_html = BeautifulSoup(webpage, features="lxml")

另一種方法:

from bs4 import BeautifulSoup
import requests

url = "https://www.g2.com/products/google-drive/reviews"
req = requests.get(url, headers={'User-Agent': 'Mozilla/5.0'})
html = req.text

parsed_html = BeautifulSoup(html, features="lxml")
print(parsed_html)

問題是這個 web 會阻止你的請求看這個答案 檢查我寫的代碼的 output 你會看到:

<title>Access denied | www.g2.com used Cloudflare to restrict access</title>

PS:你的做法沒問題,403錯誤是禁止通知。

g2.com 處理 curl 請求的指紋。 所以你應該操縱你的請求指紋。

您可以查看此Web 抓取 API 他們正在用 API 端點解決這樣的問題。 每月 1000 個請求是免費的。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM