内射老阿姨1区2区3区4区_久久精品人人做人人爽电影蜜月_久久国产精品亚洲77777_99精品又大又爽又粗少妇毛片

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

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

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

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

from bs4 import BeautifulSoup

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

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 對象

soup = BeautifulSoup(html)

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

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

上面這句代碼便是將本地 index.html 文件打開,用它來創(chuàng)建 soup 對象 下面我們來打印一下 soup 對象的內(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>

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

網(wǎng)頁名稱:Python爬蟲中如何創(chuàng)建beautifulsoup對象
文章源于:http://www.rwnh.cn/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)請盡快告知,我們將會(huì)在第一時(shí)間刪除。文章觀點(diǎn)不代表本網(wǎng)站立場,如需處理請聯(lián)系客服。電話:028-86922220;郵箱:631063699@qq.com。內(nèi)容未經(jīng)允許不得轉(zhuǎn)載,或轉(zhuǎn)載時(shí)需注明來源: 創(chuàng)新互聯(lián)

小程序開發(fā)
中西区| 探索| 长沙市| 巨鹿县| 闻喜县| 永顺县| 菏泽市| 茂名市| 原阳县| 德昌县| 科技| 平顶山市| 新邵县| 信宜市| 彩票| 六枝特区| 尼勒克县| 东兴市| 土默特左旗| 保定市| 法库县| 浮山县| 临泽县| 安徽省| 藁城市| 彝良县| 玛曲县| 屯昌县| 邛崃市| 红原县| 成安县| 拜泉县| 淳安县| 江陵县| 望奎县| 林周县| 遂川县| 泾川县| 贵港市| 察隅县| 新建县|