记录BeautifulSoup中soup.select的用法

使用soup.select(),返回类型是list

1、通过标签名查找:soup.select('xxx_标签名')

# 返回:符合该标签名所有元素的列表

2、通过类名查找:soup.select('.xxx_类名')

3、通过id名查找:soup.select('#xxx_id名')

4、组合查找,查找xxx_标签名下的xxx_类名,两者之间需用空格分开:soup.select('xxx_标签名 .xxx_类名')

5、通过子标签查找:soup.select("head > title")

6、属性查找:使用标签查找时加入属性元素,属性需要用中括号,属性和标签属于同一节点,所以不需要加空格

soup.select('xxx_标签名[xxx_属性="xxx"]')

soup.select('xxx_标签名 xxx_标签名[xxx_属性="xxx"]')

posted @ 2020-09-25 16:22  阿卷卷卷  阅读(2786)  评论(0编辑  收藏  举报