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 技術手冊 第三版
680
|
22 章 結構化文字:HTML
務,不管這個剖析是為了呈現(presenting)文件,或是,更常見的,試著
(「 scrape」)資訊。然而,處理格式不甚正確的網頁時,第三方的
BeautifulSoup 通常能提供你最後、最好的希望。在本書中,我們主要涵
BeautifulSoup,忽略 Python 標準程式庫提供的,與它「競爭」的那些
功能。
產生 HTML,以及在 HTML 中內嵌 Python,也是相當常見的任務。標準的
Python 程式庫不支援 HTML 的產生或內嵌,但你可以使用 Python 的字串
格式化(string formatting),而第三方的模組也能幫上忙。
BeautifulSoup
能讓你更動一個 HTML 樹(特別是,你能夠以程式化的方式建構一個,即
使是「從無到有」);一個替代做法是
templating
使用範本
,舉例來說,
第三方模組 jinja2 所支援的,涵蓋於後面的「jinja2 套件」中。
html.entitiesv2htmlentitydefs)模組
Python 標準程式庫中的
html.entities
模組(在v2 中,該模組名
htmlentitydefs
)提供了幾個屬性(attributes),它們全都是映射
mappings)。無論你用來剖析、編輯或產生 HTML 的一般做法為何,它
們都可以派上用場,包括後面「BeautifulSoup 第三方套件」中所涵蓋的
BeautifulSoup 套件。
codepoint2name ...
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