BeautifuSoup整理筆記

2021-06-27 15:00:43 字數 1227 閱讀 6027

find直接返回結果,select和find_all返回list

soup.title => tag

tag.name => tag_name

find/find_all用法基本相同

find_all(過濾器)

過濾器:

1 字串

2 正規表示式

3 列表

4 方法

5 true

引數:find_all(nam,attrs,recursive,text,**kwargs)

find_all(attrs=) #使用字典傳入多個屬性,可以選擇使用tag.name or 不用 : a = s.find_all('a',attrs=)

find_all(class_='link-list') ;find_all('p',class_='link-list')

find_all(text = 'overview') => 字串;find_all('p',text = 'overview') => [tag],tag 的內容是字元'overview';find_all('p',text = re.compile('beautiful')) =>[tag],tag文字內容包含'beautiful'

limit 引數:

tag.find_all('a',limit=2)

recursive 引數:

true(預設):檢索當前tag所有子孫節點

false:只檢索當前所有直接子節點

其他find/find_all:

find_parent()/find_parents();find_next_sibling()/find_next_siblings(); find_next()/find_all_next();find_previous()/find_all_previous()

css 選擇器(select()):

返回list

直接子節點: tag.select('head > title')

通過類名查詢: tag.select('.main-content')通過id查詢:tag.select('#id')

通過是否存在某個屬性查詢:tag.select('a[href]') #注意href沒有引號tag.select('tr[algin]')

通過屬性值來查詢: tag.select('a[name="ain-content"]')

修改文件樹: fo

更深入方法請檢視beautifulsoup官方文件

2019 8 2筆記整理

擴充套件 tcp ip構架 協議概述 1 查詢幫助資訊 樹狀結構 一切檔案從根開始 關於磁碟分割槽與掛載的命令 etc fstab 開機自動掛載 df h 檢視磁碟掛載情況 dd if dev zero of root image bs 1024k count 100 建立環迴裝置 虛擬磁碟 fdi...

2020 08 24 筆記整理

的組成部分 標題 頭部 主體 底部 table 定義乙個 caption 定義 的標題 thead 頭部部分 tbody 定義 的主體 資料 部分 tfoot 定義表尾,一般顯示彙總資訊 tr 定義一行 th td 來定義資料項 單元格 th 一般用於表頭,有加粗的樣式。td 一般用於主體部分,沒有...

0309筆記整理

迴圈語句 四要素 初始條件 迴圈條件 狀態改變 迴圈體 迴圈語句的格式 for int i 0 i a i 迴圈體例如 請輸入乙個數 int a int.parse console.readline int sun 1 for int i a i 1 i if鑲嵌for 例如 請輸入你所到的關卡 i...