python,提取HTML中左右没有标签的内容,怎么提取?

Python017

python,提取HTML中左右没有标签的内容,怎么提取?,第1张

我一般使用BeautifulSoup,还是比较简单的

soup=BeaitifulSoup(html,'html.parser')

要找到某各元素使用find_all方法就行

for div in soup.find_all('div'):

但是经常会遇到网站有反爬的设置,比如子结点中含有换行符,只要写个函数去掉子结点间的换行符就行

用re吧

import re

findstr = re.compile('<(.*?)>', re.S)

print(findstr.findall(s))