python - 如何使用漂亮的汤来解析多个身体标签?
问题描述
我正在尝试解析一个基本上是弹出窗口的网站注册页面。当弹出窗口打开时<body>
更改为<body class= modal-open>
。我想通过 <body class= modal-open>
. 请帮忙。我已经尝试了以下代码。
from bs4 import BeautifulSoup, SoupStrainer
from selenium import webdriver
driver.get("some site")
content = driver.page_source
while(loaded):
state = driver.execute_script('return document.readyState')
if state == 'complete':
loaded = False #this is to stop the loop if the page completely loads with its js changes
html2 = driver.execute_script("return document.documentElement.innerHTML;")
soup = BeautifulSoup(html2, "lxml")
body = soup.find_all('body', attrs={'class':['modal-open']})
print(body)
解决方案
推荐阅读
- r - 批量设置许多常量的最简单方法
- python - 我该怎么做才能使这个 matplotlib .bar 贡献图表代码在 python 中工作?
- azure - 如何使用 PowerShell 获取禁用自动关机的 azure 服务器列表?
- elasticsearch - 带有 filebeat 的 K8s Elasticsearch 在重新启动后保持“未准备好”
- html - 如何在html中将文本框和按钮保持在同一行
- bitbucket-api - Bitbucket api 为提交拉取请求返回 400
- css - 像 Firefox 一样的 CSS Scroll Snap 行为
- python - 为每个键构建一个字典,包含一组来自元组列表的关联值
- react-native - React Native 'popover' 组件与导航
- flutter - 方法“[]”在 null 上调用,但在 App 中有效