亚洲乱码中文字幕综合,中国熟女仑乱hd,亚洲精品乱拍国产一区二区三区,一本大道卡一卡二卡三乱码全集资源,又粗又黄又硬又爽的免费视频

python 3利用BeautifulSoup抓取div標(biāo)簽的方法示例

 更新時間:2017年05月28日 18:29:57   作者:Xiao|Deng  
這篇文章主要介紹了python 3利用BeautifulSoup抓取div標(biāo)簽的方法,文中給出了詳細(xì)的示例代碼供大家參考學(xué)習(xí),對大家具有一定的參考學(xué)習(xí)價值,需要的朋友們下面來一起看看吧。

前言

本文主要介紹的是關(guān)于python 3用BeautifulSoup抓取div標(biāo)簽的方法示例,分享出來供大家參考學(xué)習(xí),下面來看看詳細(xì)的介紹:

示例代碼:

# -*- coding:utf-8 -*-
#python 2.7
#XiaoDeng
#http://tieba.baidu.com/p/2460150866
#標(biāo)簽操作


from bs4 import BeautifulSoup
import urllib.request
import re


#如果是網(wǎng)址,可以用這個辦法來讀取網(wǎng)頁
#html_doc = "http://tieba.baidu.com/p/2460150866"
#req = urllib.request.Request(html_doc) 
#webpage = urllib.request.urlopen(req) 
#html = webpage.read()



html="""
<html><head><title>The Dormouse's story</title></head>
<body>
<p class="title" name="dromouse"><b>The Dormouse's story</b></p>
<p class="story">Once upon a time there were three little sisters; and their names were
<a  rel="external nofollow" class="sister" id="xiaodeng"><!-- Elsie --></a>,
<a  rel="external nofollow" rel="external nofollow" class="sister" id="link2">Lacie</a> and
<a  rel="external nofollow" class="sister" id="link3">Tillie</a>;
<a  rel="external nofollow" rel="external nofollow" class="sister" id="xiaodeng">Lacie</a>
and they lived at the bottom of a well.</p>
<div class="ntopbar_loading"><img src="http://simg.sinajs.cn/blog7style/images/common/loading.gif">加載中…</div>

<div class="SG_connHead">
   <span class="title" comp_title="個人資料">個人資料</span>
   <span class="edit">
      </span>
<div class="info_list">  
         <ul class="info_list1">
     <li><span class="SG_txtc">博客等級:</span><span id="comp_901_grade"><img src="http://simg.sinajs.cn/blog7style/images/common/sg_trans.gif" real_src="http://simg.sinajs.cn/blog7style/images/common/number/9.gif" /></span></li>
     <li><span class="SG_txtc">博客積分:</span><span id="comp_901_score"><strong>0</strong></span></li>
     </ul>
     <ul class="info_list2">
     <li><span class="SG_txtc">博客訪問:</span><span id="comp_901_pv"><strong>3,971</strong></span></li>
     <li><span class="SG_txtc">關(guān)注人氣:</span><span id="comp_901_attention"><strong>0</strong></span></li>
     <li><span class="SG_txtc">獲贈金筆:</span><strong id="comp_901_d_goldpen">0支</strong></li>
     <li><span class="SG_txtc">贈出金筆:</span><strong id="comp_901_r_goldpen">0支</strong></li>
     <li class="lisp" id="comp_901_badge"><span class="SG_txtc">榮譽徽章:</span></li>
     </ul>
     </div>
<div class="atcTit_more"><span class="SG_more"><a  rel="external nofollow" rel="external nofollow" target="_blank">更多&gt;&gt;</a></span></div>     
<p class="story">...</p>
"""
soup = BeautifulSoup(html, 'html.parser') #文檔對象



# 類名為xxx而且文本內(nèi)容為hahaha的div
for k in soup.find_all('div',class_='atcTit_more'):#,string='更多'
 print(k)
 #<div class="atcTit_more"><span class="SG_more"><a  rel="external nofollow" rel="external nofollow" target="_blank">更多&gt;&gt;</a></span></div>

總結(jié)

以上就是這篇文章的全部內(nèi)容了,希望本文的內(nèi)容對大家的學(xué)習(xí)或者工作能帶來一定的幫助,如果有疑問大家可以留言交流,謝謝大家腳本之家的支持。

相關(guān)文章

  • Python中Threading用法詳解

    Python中Threading用法詳解

    本篇文章給大家介紹了Python中Threading的詳細(xì)用法,需要的朋友跟著小編一起學(xué)習(xí)下吧。
    2017-12-12
  • Python3.4學(xué)習(xí)筆記之常用操作符,條件分支和循環(huán)用法示例

    Python3.4學(xué)習(xí)筆記之常用操作符,條件分支和循環(huán)用法示例

    這篇文章主要介紹了Python3.4常用操作符,條件分支和循環(huán)用法,結(jié)合實例形式較為詳細(xì)的分析了Python3.4常見的數(shù)學(xué)運算、邏輯運算操作符,條件分支語句,循環(huán)語句等功能與基本用法,需要的朋友可以參考下
    2019-03-03
  • 查看已安裝tensorflow版本的方法示例

    查看已安裝tensorflow版本的方法示例

    這篇文章主要介紹了查看已安裝tensorflow版本的方法示例,文中通過示例代碼介紹的非常詳細(xì),對大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價值,需要的朋友們下面隨著小編來一起學(xué)習(xí)學(xué)習(xí)吧
    2020-04-04
  • Python 如何獲取目錄下的文件列表,并自然排序

    Python 如何獲取目錄下的文件列表,并自然排序

    這篇文章主要介紹了Python 如何獲取目錄下的文件列表,并自然排序的操作,具有很好的參考價值,希望對大家有所幫助。如有錯誤或未考慮完全的地方,望不吝賜教
    2021-05-05
  • numpy如何獲取array中數(shù)組元素的索引位置

    numpy如何獲取array中數(shù)組元素的索引位置

    這篇文章主要介紹了numpy獲取array中數(shù)組元素的索引位置,本文給大家介紹的非常詳細(xì),對大家的學(xué)習(xí)或工作具有一定的參考借鑒價值,需要的朋友可以參考下
    2023-01-01
  • Elasticsearch之倒排索引及索引操作

    Elasticsearch之倒排索引及索引操作

    這篇文章主要為大家介紹了Elasticsearch之倒排索引及索引操作示例,有需要的朋友可以借鑒參考下,希望能夠有所幫助,祝大家多多進(jìn)步,早日升職加薪
    2022-04-04
  • python中while和for的區(qū)別總結(jié)

    python中while和for的區(qū)別總結(jié)

    在本篇內(nèi)容里小編給大家分享的是關(guān)于python中while和for的區(qū)別以及相關(guān)知識點,需要的朋友們可以學(xué)習(xí)下。
    2019-06-06
  • pyqt 實現(xiàn)為長內(nèi)容添加滑輪 scrollArea

    pyqt 實現(xiàn)為長內(nèi)容添加滑輪 scrollArea

    今天小編就為大家分享一篇pyqt 實現(xiàn)為長內(nèi)容添加滑輪 scrollArea,具有很好的參考價值,希望對大家有所幫助。一起跟隨小編過來看看吧
    2019-06-06
  • python生成excel的實例代碼

    python生成excel的實例代碼

    這篇文章主要為大家詳細(xì)介紹了python生成excel的實例代碼,具有一定的參考價值,感興趣的小伙伴們可以參考一下
    2017-11-11
  • 淺談Python type的使用

    淺談Python type的使用

    今天小編就為大家分享一篇淺談Python type的使用,具有很好的參考價值,希望對大家有所幫助。一起跟隨小編過來看看吧
    2019-11-11

最新評論