【发布时间】:2023-01-13 20:43:06
【问题描述】:
我想要 html 文件中存在的 divs 的总数。
我想要 python 中的解决方案。
我已经尝试按照代码使用类查找divs,但现在我想要那个divs 的大小。
from bs4 import BeautifulSoup
import random
HTMLFile = open("/home/earth/sample.html", "r")
file = HTMLFile.read()
print(file)
S = BeautifulSoup(file, 'lxml')
Des = S.body
Attr_Tag = [e.name for e in Des.descendants if e.name is not None]
print(Attr_Tag)
mydivs = S.findAll('div',class_="col")
#mydivs=S.select('.col')
print(mydivs)
【问题讨论】: