python 3利用BeautifulSoup抓取div标签的方法示例

python 3利用BeautifulSoup抓取div标签的方法示例,第1张

概述前言本文主要介绍的是关于python3用BeautifulSoup抓取div标签的方法示例,分享出来供大家参考学习,下面来看看详细的介绍:

前言

本文主要介绍的是关于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  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" rel="external nofollow"  ID="xiaodeng"><!-- ElsIE --></a>,<a href="http://example.com/lacIE" rel="external nofollow" rel="external nofollow"  ID="link2">LacIE</a> and<a href="http://example.com/tillIE" rel="external nofollow"  ID="link3">TillIE</a>;<a href="http://example.com/lacIE" rel="external nofollow" rel="external nofollow"  ID="xiaodeng">LacIE</a>and they lived at the bottom of a well.</p><div ><img src="/uploads/201706/26/14984792531.gif">加载中…</div><div >   <span  comp_title="个人资料">个人资料</span>   <span >      </span><div >           <ul >     <li><span >博客等级:</span><span ID="comp_901_grade"><img src="/uploads/201706/26/14984792532.gif" real_src="/uploads/201706/26/14984792533.gif" /></span></li>     <li><span >博客积分:</span><span ID="comp_901_score"><strong>0</strong></span></li>     </ul>     <ul >     <li><span >博客访问:</span><span ID="comp_901_pv"><strong>3,971</strong></span></li>     <li><span >关注人气:</span><span ID="comp_901_attention"><strong>0</strong></span></li>     <li><span >获赠金笔:</span><strong ID="comp_901_d_goldpen">0支</strong></li>     <li><span >赠出金笔:</span><strong ID="comp_901_r_goldpen">0支</strong></li>     <li  ID="comp_901_badge"><span >荣誉徽章:</span></li>     </ul>     </div><div ><span ><a href="http://blog.sina.com.cn/" rel="external nofollow" rel="external nofollow" target="_blank">更多>></a></span></div>     <p >...</p>"""soup = BeautifulSoup(HTML,'HTML.parser') #文档对象# 类名为xxx而且文本内容为hahaha的divfor k in soup.find_all('div',class_='atcTit_more'):#,string='更多' print(k) #<div ><span ><a href="http://blog.sina.com.cn/" rel="external nofollow" rel="external nofollow" target="_blank">更多>></a></span></div>

总结

以上就是这篇文章的全部内容了,希望本文的内容对大家的学习或者工作能带来一定的帮助,如果有疑问大家可以留言交流,谢谢大家编程小技巧的支持。

总结

以上是内存溢出为你收集整理的python 3利用BeautifulSoup抓取div标签的方法示例全部内容,希望文章能够帮你解决python 3利用BeautifulSoup抓取div标签的方法示例所遇到的程序开发问题。

如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。

欢迎分享,转载请注明来源:内存溢出

原文地址: http://www.outofmemory.cn/langs/1202030.html

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
上一篇 2022-06-04
下一篇 2022-06-04

发表评论

登录后才能评论

评论列表(0条)

保存