BeautifulSoup

bs4 基本使用

pip install bs4

https://beautifulsoup.readthedocs.io/zh_CN/v4.4.0/

将html 转换为

  1. 将页面源代码交给BeautifulSoup, 进行解析
  2. find 只找第一个满足条件的
  3. find_all 所有满足条件的
  4. 通过get 可以直接拿到属性的值
from bs4 import BeautifulSoup

page = BeautifulSoup(resp.text, "html.parser") # 将页面源代码交给BeautifulSoup, 并指明为html格式
1. 
page.find("table", class_="hq_table") # 匹配table 标签, class 为 hq_table
2.
page.find("table", attrs={"class": "hq_table"} # 匹配table 标签, class 为 hq_table

posted @ 2021-03-25 20:17  ShanCe-刘勇  阅读(29)  评论(0编辑  收藏  举报