我正在尝试解析一个基本上是弹出窗口的网站注册页面。当弹出窗口打开时<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)