天天看點

BeautifulSoup 安裝使用

Linux環境

1. 安裝

方法一:

解壓:tar -xzvf beautifulsoup4-4.2.0.tar.gz

安裝:進入解壓後的目錄

方法二(快速安裝)

2. 引用(python環境下)

3. 使用

案例

1

2

3

4

5

6

7

8

9

10

11

12

13

<code>html_doc = """</code>

<code>&lt;</code><code>html</code><code>&gt;&lt;</code><code>head</code><code>&gt;&lt;</code><code>title</code><code>&gt;The Dormouse's story&lt;/</code><code>title</code><code>&gt;&lt;/</code><code>head</code><code>&gt;</code>

<code>&lt;</code><code>p</code> <code>class="title"&gt;&lt;</code><code>b</code><code>&gt;The Dormouse's story&lt;/</code><code>b</code><code>&gt;&lt;/</code><code>p</code><code>&gt;</code>

<code>&lt;</code><code>p</code> <code>class="story"&gt;Once upon a time there were three little sisters; and their names were</code>

<code>&lt;</code><code>a</code> <code>href="http://example.com/elsie" class="sister" id="link1"&gt;Elsie&lt;/</code><code>a</code><code>&gt;,</code>

<code>&lt;</code><code>a</code> <code>href="http://example.com/lacie" class="sister" id="link2"&gt;Lacie&lt;/</code><code>a</code><code>&gt; and</code>

<code>&lt;</code><code>a</code> <code>href="http://example.com/tillie" class="sister" id="link3"&gt;Tillie&lt;/</code><code>a</code><code>&gt;;</code>

<code>and they lived at the bottom of a well.&lt;/</code><code>p</code><code>&gt;</code>

<code>&lt;</code><code>p</code> <code>class="story"&gt;...&lt;/</code><code>p</code><code>&gt;</code>

<code>"""</code>

開始

找到所有的a

列印每個a中的資訊

<a></a>

本文轉自jihite部落格園部落格,原文連結:http://www.cnblogs.com/kaituorensheng/p/3722913.html,如需轉載請自行聯系原作者