国产探花免费观看_亚洲丰满少妇自慰呻吟_97日韩有码在线_资源在线日韩欧美_一区二区精品毛片,辰东完美世界有声小说,欢乐颂第一季,yy玄幻小说排行榜完本

首頁 > 編程 > Python > 正文

python 3利用BeautifulSoup抓取div標簽的方法示例

2020-01-04 17:15:01
字體:
來源:轉載
供稿:網友

前言

本文主要介紹的是關于python 3用BeautifulSoup抓取div標簽的方法示例,分享出來供大家參考學習,下面來看看詳細的介紹:

示例代碼:

# -*- coding:utf-8 -*-#python 2.7#XiaoDeng#http://tieba.baidu.com/p/2460150866#標簽操作from bs4 import BeautifulSoupimport urllib.requestimport re#如果是網址,可以用這個辦法來讀取網頁#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 href="http://example.com/elsie" rel="external nofollow" class="sister" id="xiaodeng"><!-- Elsie --></a>,<a href="http://example.com/lacie" rel="external nofollow" rel="external nofollow" class="sister" id="link2">Lacie</a> and<a href="http://example.com/tillie" rel="external nofollow" class="sister" id="link3">Tillie</a>;<a href="http://example.com/lacie" 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">關注人氣:</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 href="http://blog.sina.com.cn/" rel="external nofollow" rel="external nofollow" target="_blank">更多>></a></span></div>     <p class="story">...</p>"""soup = BeautifulSoup(html, 'html.parser') #文檔對象# 類名為xxx而且文本內容為hahaha的divfor k in soup.find_all('div',class_='atcTit_more'):#,string='更多' print(k) #<div class="atcTit_more"><span class="SG_more"><a href="http://blog.sina.com.cn/" rel="external nofollow" rel="external nofollow" target="_blank">更多>></a></span></div>

總結

以上就是這篇文章的全部內容了,希望本文的內容對大家的學習或者工作能帶來一定的幫助,如果有疑問大家可以留言交流,謝謝大家VEVB武林網的支持。

發表評論 共有條評論
用戶名: 密碼:
驗證碼: 匿名發表
主站蜘蛛池模板: 余干县| 毕节市| 奇台县| 蒲江县| 卢湾区| 隆德县| 双桥区| 乾安县| 永寿县| 武川县| 张家口市| 小金县| 炎陵县| 鹤庆县| 南平市| 仪征市| 达孜县| 阿拉善右旗| 唐河县| 南安市| 孝义市| 百色市| 茌平县| 岚皋县| 吴江市| 年辖:市辖区| 磐石市| 察隅县| 瑞安市| 铜陵市| 峡江县| 图们市| 巩义市| 太湖县| 伊吾县| 扶余县| 沂水县| 凤庆县| 天祝| 大丰市| 昆山市|