服务器停止随机响应获取请求

问题描述 投票:0回答:0

我正在使用 get request 编写我的第一个网络抓取项目。它在 For 循环中运行良好,但它随机停止 For 循环的整数值并抛出错误

---------------------------------------------------------------------------
AttributeError                            Traceback (most recent call last)
/Users/jatinkashyap/Documents/Work/web_crawl/UCC/final.py in line 44
     42 page = requests.get(URL)
     43 soup = BeautifulSoup(page.content, "html.parser")
---> 44 name = soup.find(id="ContentPlaceHolder1_LocationNameLbl").get_text()
     45 city = soup.find(id="ContentPlaceHolder1_city").get_text()
     46 state = soup.find(id="ContentPlaceHolder1_state").get_text()

AttributeError: 'NoneType' object has no attribute 'get_text'

如果我手动通过 Chrome 浏览器访问该网页,则会出现此错误,如下所示

  We apologize for the inconvenience, however, there seems to be an issue with your search.
Please click here to search again.

如果我手动进一步浏览网站 1-2 分钟,然后问题网页再次出现,上面的文本(我们道歉......)消失并且代码也开始工作,然后再次在 For 循环变量的其他值处遇到 AttributeError .我在 8 到 15 秒之间的随机时间对服务器执行 ping 操作。阻止我几分钟是服务器的技术吗?但另一方面,它不能自动阻止我,因为它让我在随机时间回到服务器,例如 1 分钟后或 5 分钟后等。我试图废弃一个公共工作板以获得 4000 次 ping,大约 8-相隔15秒。任何帮助将不胜感激。

python-3.x pandas python-requests
© www.soinside.com 2019 - 2024. All rights reserved.