bs4解析xml文件

使用BS4解析XML文件用法

1. html.parser

from bs4 import BeautifulSoup

soup = BeautifulSoup(html, "html.parser")
两个参数:第一个参数是要解析的html文本,第二个参数是使用那种解析器,对于HTML来讲就是html.parser,这个是bs4自带的解析器
2.

 soup = BeautifulSoup(html, "lxml")

查找所有符合条件的标签

a)使用tag查找

soup.find_all('b')
b)正则表达式查找
soup.find_all(re.compile("^b"))

c)按列表中提供的tab查找
soup.find_all(["a", "b"])
 

参考链接:

https://www.cnblogs.com/gl1573/p/9480022.html
  

猜你喜欢

转载自www.cnblogs.com/i-shu/p/11487438.html
BS4
今日推荐