python - 使用 BS4 + Python 从动态网站导出数据:
问题描述
我想将以下网站中的所有商店数据导出到 excel 文件中: https ://www.ybpn.de/ihre-parfuemerien
问题:地图是“动态的”,因此当您输入邮政编码时会加载所需的数据。
需要的数据存储在 div-class "storefinder__list-item" 中,在 data-"storefinder-reference" div-class 中具有唯一引用,例如:data-storefinder-reference="132"
我试过了:
soup.find("div", {"data-storefinder-reference": "132"})
但输出是:无
我认为这个问题是由于页面是动态的,因此当您输入邮政编码时会加载所需的数据。因此,当我搜索参考 ID“132”时,它的“那里”,但没有加载到网站上,并且 bs4 找不到这个 ID。
有什么想法可以改进代码吗?
解决方案
为此,您可能需要研究selenium和/或“firefox-headless”等工具。
尤其是 selenium 允许您使用 Python “远程控制”网页
这是一个教程:https ://realpython.com/modern-web-automation-with-python-and-selenium/
推荐阅读
- .net-core - 如何更改 Azure Web 应用程序的权限,以便我可以通过 FTP 将文件上传到它?
- java - 如何使用 GSON 或任何其他序列化程序将其解析为 POJO 模型
- powerbi - Microsoft PowerBI 匹配多个值是使用 ID 和日期的单独表
- javascript - 如何在不刷新页面的情况下更改 URL?
- c# - Google Calendar API 异常“访问被拒绝。” .NET Core Web App 在本地运行良好,在 Azure 上发布时引发异常
- reactjs - 将函数传递给孩子的子组件
- python - 对熊猫数据字段的速记引用?
- python - 遍历数据块并为该块中的每个元素再次迭代
- python - Discord.py 授予用户对文本频道的权限
- java - 我如何知道在通知中单击了哪个按钮?