首页 > 解决方案 > 如何使用漂亮的汤来解析多个身体标签?

问题描述

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

标签: pythonselenium-webdriverbeautifulsoupxml-parsing

解决方案


推荐阅读