欧美一区二区三区老妇人-欧美做爰猛烈大尺度电-99久久夜色精品国产亚洲a-亚洲福利视频一区二区

Python爬蟲(chóng)中如何創(chuàng)建beautifulsoup對(duì)象

小編給大家分享一下Python爬蟲(chóng)中如何創(chuàng)建 beautifulsoup 對(duì)象,希望大家閱讀完這篇文章后大所收獲,下面讓我們一起去探討吧!

樂(lè)至ssl適用于網(wǎng)站、小程序/APP、API接口等需要進(jìn)行數(shù)據(jù)傳輸應(yīng)用場(chǎng)景,ssl證書(shū)未來(lái)市場(chǎng)廣闊!成為創(chuàng)新互聯(lián)建站的ssl證書(shū)銷售渠道,可以享受市場(chǎng)價(jià)格4-6折優(yōu)惠!如果有意向歡迎電話聯(lián)系或者加微信:18980820575(備注:SSL證書(shū)合作)期待與您的合作!

首先必須要導(dǎo)入 bs4 庫(kù)

from bs4 import BeautifulSoup

我們創(chuàng)建一個(gè)字符串,后面的例子我們便會(huì)用它來(lái)演示

html = """
<html><head><title>The Dormouse's story</title></head>
<body>
<p name="dromouse"><b>The Dormouse's story</b></p>
<p>Once upon a time there were three little sisters; and their names were
<a href="http://example.com/elsie" id="link1"><!-- Elsie --></a>,
<a href="http://example.com/lacie" id="link2">Lacie</a> and
<a href="http://example.com/tillie" id="link3">Tillie</a>;
and they lived at the bottom of a well.</p>
<p>...</p>
"""

創(chuàng)建 beautifulsoup 對(duì)象

soup = BeautifulSoup(html)

另外,我們還可以用本地 HTML 文件來(lái)創(chuàng)建對(duì)象,例如

soup = BeautifulSoup(open('index.html'))

上面這句代碼便是將本地 index.html 文件打開(kāi),用它來(lái)創(chuàng)建 soup 對(duì)象 下面我們來(lái)打印一下 soup 對(duì)象的內(nèi)容,格式化輸出

print soup.prettify()

輸出結(jié)果:

<html>
 <head>
  <title>
   The Dormouse's story
  </title>
 </head>
 <body>
  <p name="dromouse">
   <b>
    The Dormouse's story
   </b>
  </p>
  <p>
   Once upon a time there were three little sisters; and their names were
   <a href="http://example.com/elsie" id="link1">
    <!-- Elsie -->
   </a>
   ,
   <a href="http://example.com/lacie" id="link2">
    Lacie
   </a>
   and
   <a href="http://example.com/tillie" id="link3">
    Tillie
   </a>
   ;
and they lived at the bottom of a well.
  </p>
  <p>
   ...
  </p>
 </body>
</html>

看完了這篇文章,相信你對(duì)Python爬蟲(chóng)中如何創(chuàng)建 beautifulsoup 對(duì)象有了一定的了解,想了解更多相關(guān)知識(shí),歡迎關(guān)注創(chuàng)新互聯(lián)行業(yè)資訊頻道,感謝各位的閱讀!

網(wǎng)頁(yè)名稱:Python爬蟲(chóng)中如何創(chuàng)建beautifulsoup對(duì)象
文章源于:http://chinadenli.net/article38/gspppp.html

成都網(wǎng)站建設(shè)公司_創(chuàng)新互聯(lián),為您提供網(wǎng)站改版ChatGPT品牌網(wǎng)站制作網(wǎng)站建設(shè)企業(yè)建站云服務(wù)器

廣告

聲明:本網(wǎng)站發(fā)布的內(nèi)容(圖片、視頻和文字)以用戶投稿、用戶轉(zhuǎn)載內(nèi)容為主,如果涉及侵權(quán)請(qǐng)盡快告知,我們將會(huì)在第一時(shí)間刪除。文章觀點(diǎn)不代表本網(wǎng)站立場(chǎng),如需處理請(qǐng)聯(lián)系客服。電話:028-86922220;郵箱:631063699@qq.com。內(nèi)容未經(jīng)允許不得轉(zhuǎn)載,或轉(zhuǎn)載時(shí)需注明來(lái)源: 創(chuàng)新互聯(lián)

小程序開(kāi)發(fā)