除某些特定的div之外,我正在使用bs4解析url并提取HTML中的body标签。一个简单的例子:我需要获取除div b之外的所有代码。
<body>
<div class="a"></div>
<div class="b"></div>
<div class="a"></div>
</body>
我正在使用Standart bs4设置:
import requests
from bs4 import BeautifulSoup
site = 'http://www.example.com'
response = requests.get(site).text
response = response.encode('latin-1')
soup = BeautifulSoup(response, 'html.parser')
要提到的是,在实际的网站上,HTML代码比示例中要复杂得多。 我已经尝试过使用soup.extract和分解,但是并没有设法使它起作用。任何想法我怎么能做到这一点?谢谢。