beautifulsoup - 请求响应对象:如何检查页面加载完全(动态内容)?
问题描述
我正在做以下事情。创建会话后,我正在对页面进行简单的 GET 操作。问题是,如果这个页面充满了动态部分,所以需要 10-30 秒才能完全生成我感兴趣的 HTML。我用 BeautifulSoup 处理的 HTML。
如果我处理响应对象的速度太快,我就得不到我想要的数据。我已经使用“睡眠”暂停了一段时间,但我认为应该有更好的方法来检查完整的页面加载。我不能依赖状态 200 代码,因为在主页内,动态部分仍在加载。
我的代码:
s = requests.session()
r = s.get('URL')
time.sleep(20)
... code to process response object...
我试图通过 BeautifulSoup 搜索更“优雅”地检查某个标签,但似乎不起作用。
我的代码:
title_found = False
while title_found == False:
soupje = BeautifulSoup(r.text, 'html.parser')
title_found_in_html_full = soupje.find(id='titleView!1Title')
if title_found_in_html_full is not None:
title_found_in_html = title_found_in_html_full.get('id')
if title_found_in_html == 'titleView!1Title':
title_found = True
随着页面加载,响应对象是否会随着时间而变化?
有什么建议么?谢谢
解决方案
推荐阅读
- java - 尝试从空对象引用上的字段“android.view.View androidx.recyclerview.widget.RecyclerView$ViewHolder.itemView”读取
- jquery - 调整元素大小时,jQuery 文档准备好不起作用
- java - viewmodelfactory 和使用活动模块的视图模型注入之间的区别
- c# - AddAuthentication Service 向 UseAuthorization 中间件注入了什么?
- java - 获取 NoSuchElementException:没有这样的元素:无法找到元素
- node.js - 错误:找不到模块“aws-api-gateway-client”
- c# - 如何在 C# 中调用带有字符串变量的函数
- bash - shell 脚本从数组中声明关联变量
- objective-c - Xcode 是否有类似于 IntelliJ 的“生成构造函数”的“生成初始化程序”命令?
- javascript - 我的 React Typescript 计数器中的逻辑 NaN 错误以获取胜率