Skip to Content
Python 技術手冊 第三版
book

Python 技術手冊 第三版

by lex Martelli, Anna Martelli Ravenscroft, Steve Holden
January 2018
Intermediate to advanced content levelIntermediate to advanced
856 pages
17h 17m
Chinese
GoTop Information, Inc.
Content preview from Python 技術手冊 第三版
690
|
22 章 結構化文字:HTML
搜尋方法的引數
每個搜尋方法都有三個選擇性引數:
name
attrs
string
name
string
過濾器
filters
,如本節後面中所描述的;
attrs
是一個
dict
,也會
在本節後面描述。此外,僅限於
find
find_all
(而不適用其他搜尋方
法),可選擇性地以引數
recursive=False
被呼叫,以限制在子節點中搜
尋,而非所有的子裔。
任何會回傳一個串列的搜尋方法(即名稱為複數的,或以
find_all
開頭
的)都可以有選擇性的具名引數
limit
,若有傳入,其值就會是一個整數,
對所回傳的串列設下長度的一個上界。
在這些選擇性引數之後,每個搜尋方法都可以選擇性地有任何數目的任意
具名引數,其名稱可以是任何的識別字(除了搜尋方法的特定引數之名
稱),而其值為一個過濾器。
搜尋方法引數:過濾器
一個
過濾器
filter
會被套用到一個
目標
target
,這個目標可以是
一個標記的名稱(傳入作為
name
引數時)、一個
Tag
string
或一個
NavigableString
的文字內容(傳入作為
string
時),或一個
Tag
的屬性
(傳入作為具名引數的值,或在
attrs
中傳入時)。每個過濾器可以是:
一個
Unicode
字串
過濾器會在此字串完全等於目標時匹配成功
一個位元組字串
bytestring
它會以
utf8
被解碼為 Unicode,然後過濾器會在所產生的 Unicode
串完全等於目標時,匹配成功
一個正規表達式物件
RE
re.compile ...
Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Start your free trial

You might also like

測試驅動開發|使用 Python

測試驅動開發|使用 Python

Harry J.W. Percival
Linux 内核观测技术BPF

Linux 内核观测技术BPF

David Calavera, Lorenzo Fontana

Publisher Resources

ISBN: 9789864766819