import re
from bs4 import BeautifulSoup, Comment
soup = BeautifulSoup(myhtml)
comments = soup.find_all(text=lambda text: isinstance(text, Comment))
要在注释中找到div
for comment in comments:
cmnt_soup = BeautifulSoup(comment)
divs = cmnt_soup.find_all('div', attrs={"id": re.compile(r'IAMCOMMENT_\d+')})
# do things with the divs
我将使用
BeautifulSoup's
内置的find_all
函数:若要解析表单注释,首先需要找到html的注释。一种方法是:
要在注释中找到
div
相关问题 更多 >
编程相关推荐