【问题标题】:Web Scraping Customer Reviews网页抓取客户评论
【发布时间】:2021-04-24 00:13:24
【问题描述】:

我正在尝试从 G2 抓取客户评论,作为我工作项目的一部分,但收到 403 错误。有什么想法可以解决这个问题吗?

HTTPError:HTTP 错误 403:禁止

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")

【问题讨论】:

    标签: python web-scraping


    【解决方案1】:

    另一种方法:

    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)
    

    问题是这个网站会阻止你的请求观看这个answer。检查我写的代码的输出,你会看到:

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

    PS:你的做法没问题,403错误是禁止通知。

    【讨论】:

      【解决方案2】:

      g2.com 处理 curl 请求的指纹。所以你应该操纵你的请求指纹。

      您可以查看此Web Scraping API。 他们正在使用 API 端点解决此类问题。每月 1000 个请求是免费的。

      【讨论】:

      • 您的答案可以通过额外的支持信息得到改进。请edit 添加更多详细信息,例如引用或文档,以便其他人可以确认您的答案是正确的。你可以找到更多关于如何写好答案的信息in the help center
      猜你喜欢
      • 1970-01-01
      • 2019-12-04
      • 2017-07-28
      • 1970-01-01
      • 2020-03-05
      • 2019-12-07
      • 1970-01-01
      • 1970-01-01
      • 2019-05-08
      相关资源
      最近更新 更多