当前位置: 首页 > 工具软件 > BS.Play > 使用案例 >

学习笔记(23):150讲轻松搞定Python网络爬虫-bs4-select方法

阎单鹗
2023-12-01

立即学习:https://edu.csdn.net/course/play/24756/280701?utm_source=blogtoedu

select:

from bs4 import BeautifulSoup

html="""   """

soup = BeautifulSoup(html,"lxml")

(1)通过标签名查找:

print(soup.select('a'))

(2)通过类名查找:

print(soup.select('.sister'))

(3)通过id查找:

print(soup.select('#link1'))

(4)组合查找:

print(soup.select('p #link1'))

或者:

print(soup.select('head > title'))

(5)通过属性查找:

print(soup.select('a[href=" "]'))

(6)获取内容:

print(soup.select('title')[0].get_text())

 

 类似资料: