python - 谷歌合作实验室: Access Denied You don't have permission to access "website" on this server

标签 python beautifulsoup automation google-cloud-platform google-colaboratory

我正在尝试使用 beautiful soup 在 google colab 上抓取网站。我能够在本地计算机上抓取内容,但是当我尝试在云上抓取内容时。我收到错误。

'\nAccess Denied\n\nAccess Denied\n \nYou don\'t have permission to access "http://www.justdial.com/Bangalore/Spardha-Mithra-IAS-KAS-Coaching-Centre-Opposite-Maruthi-Medicals-Vijayanagar/080PXX80-XX80-140120184741-R6P8_BZDET?" on this server.\nReference #18.740f1160.1544263996.61a6bb6e\n\n\n'

当我在本地计算机上运行相同的代码时,它工作正常。

import requests
import re
from bs4 import BeautifulSoup
url = 'https://www.justdial.com/Bangalore/Spardha-Mithra-IAS-KAS-Coaching-Centre-Opposite-Maruthi-Medicals-Vijayanagar/080PXX80-XX80-140120184741-R6P8_BZDET?xid=QmFuZ2Fsb3JlIEJhbmsgRXhhbSBUdXRvcmlhbHM='
res  = requests.get(url, headers  = {'User-Agent': 'Mozilla/5.0'})
soup = BeautifulSoup(res.content, 'html.parser')
print(res)

输出:

<Response [403]>

为什么会发生这种情况,有什么办法可以消除它。

最佳答案

很确定这是服务器端速率限制。你的代码在 colab 中对我来说工作得很好。 您可以尝试 colab 的“重置所有运行时”功能来分配新的虚拟机,以排除您运行的其他笔记本代码带来的任何副作用。

关于python - 谷歌合作实验室: Access Denied You don't have permission to access "website" on this server,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/53681507/

相关文章:

python - 与 aiohttp 网络服务器共享状态

Python 的 'mock' - 响应参数

c++ - 使用 C++ Builder 5 实现 Word 自动化

python - 在定义函数时,非默认参数跟在默认参数之后

python - 无法从源解析导入 "bs4"

python - 将元素从 BeautifulSoup 发送到 Selenium

python - Bs4 select_one vs find

java - 我想验证网站的菜单栏选项卡而不是单击它们

java - 使用 Saucelabs 和 QAF 框架并行执行多个操作系统、浏览器

python - 为什么在 Python 路径中需要 4 个反斜杠?