Python请求:Glassdoor.com上出现403错误

2024-04-23 08:50:20 发布

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

我正在尝试使用请求访问Glassdoor上的公司简介,但该网站不断返回403错误。几天前我使用了相同的代码,没有任何问题,所以我不确定问题出在哪里。我已经尝试过添加标题,但也没有效果。有趣的是,Python请求返回以下内容:

Sorry, we had some trouble processing your request. Most of the time, this problem can be fixed by reloading the page. Click <a class="reload" href=""here</a to reload. If this problem persists, it may be because there's an issue with our site right now.

但是,当我在普通浏览器上访问同一站点时,所有内容都会正常加载。代码如下:

import requests
AAPL = "https://www.glassdoor.com/Reviews/Apple-Reviews-E1138.htm"
    
headers = {"User-Agent": foo, 
           "referer": "https://www.google.com/"}

page = requests.get(AAPL, headers=headers)

当我尝试访问Glassdoor以外的网站时,没有问题,因此我怀疑问题尤其在于Glassdoor。然而,这并不能解释为什么当我使用普通浏览器访问该网站时,加载该网站没有问题

编辑:

显然,以上述方式提出请求违反了Glassdoor的服务条款。Glassdoor的API也受到限制,因此是否有其他方法参考该网站?我所要做的就是提取审核数据(评级和日期)供个人使用


Tags: the代码https网站wwwpage浏览器be