我正试着从reddit网页上获取视频。我用Python和靓汤来做工作。那个下面的代码有时会返回结果,有时在我重新运行代码时不会返回结果。我不确定我哪里出错了。有人能帮忙吗?我是python的新手,所以请容忍我。在
import requests
from bs4 import BeautifulSoup
page = requests.get('https://www.reddit.com/r/FortNiteBR/comments/afjbbp/just_trying_to_revive_my_buddy_and_then_he_got/')
soup = BeautifulSoup(page.text, 'html.parser')
source_tags = soup.find_all('source')
print(source_tags)
如果您在
page = requests.get('https:/.........')
之后执行print (page)
,您将看到您获得一个成功的<Response [200]>
但是如果您再次快速运行它,您将得到
<Response [429]>
“HTTP 429 Too Many Requests response status code(HTTP 429 Too Many Requests response status code)表示用户在给定时间内发送了太多请求(“速率限制”)。“Source here
另外,如果您查看html源代码,您会看到:
要添加标题并避免使用429附加模块:
^{pr2}$完整代码:
输出:
并且在等待一两秒钟后重新运行没有问题
我尝试了下面的代码,它是为我的每一个请求,增加了30秒的超时。在
相关问题 更多 >
编程相关推荐