前言

本文主要介绍的是关于python 3用BeautifulSoup抓取div标签的方法示例,分享出来供大家参考学习,下面来看看详细的介绍:
示例代码:
# -*- coding:utf-8 -*-
#python 2.7
#XiaoDeng
#http://tieba.baidu.com/p/2460150866
#标签操作
from bs4 import BeautifulSoup
import urllib.request
import 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的div
for 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>
总结
以上就是这篇文章的全部内容了,希望本文的内容对大家的学习或者工作能带来一定的帮助,如果有疑问大家可以留言交流,谢谢大家的支持。
# beautifulsoup
# div
# beautifulsoup获取div
# python3beautifulsoup
# Python爬虫包 BeautifulSoup 递归抓取实例详解
# python基于BeautifulSoup实现抓取网页指定内容的方法
# python使用beautifulsoup从爱奇艺网抓取视频播放
# 使用python BeautifulSoup库抓取58手机维修信息
# python BeautifulSoup使用方法详解
# python 解析html之BeautifulSoup
# Python使用BeautifulSoup库解析HTML基本使用教程
# python利用beautifulSoup实现爬虫
# python使用BeautifulSoup分页网页中超链接的方法
# Python爬虫beautifulsoup4常用的解析方法总结
# python3 BeautifulSoup模块使用字典的方法抓取a标签内的数据示例
# 博客
# 的是
# 可以用
# 来看看
# 这篇文章
# 谢谢大家
# 获赠
# 文档
# 加载中
# 有疑问
# title
# story
# body
# Dormouse
# head
# html
# urlopen
# webpage
# gt
# lt
相关文章:
SAX解析器是什么,它与DOM在处理大型XML文件时有何不同?
宝塔建站助手安装配置与建站模板使用全流程解析
建站之星下载版如何获取与安装?
制作公司内部网站有哪些,内网如何建网站?
长沙做网站要多少钱,长沙国安网络怎么样?
齐河建站公司:营销型网站建设与SEO优化双核驱动策略
外贸公司网站制作哪家好,maersk船公司官网?
网站图片在线制作软件,怎么在图片上做链接?
建站主机功能解析:服务器选择与快速搭建指南
如何快速生成凡客建站的专业级图册?
如何选择高效可靠的多用户建站源码资源?
中山网站推广排名,中山信息港登录入口?
猪八戒网站制作视频,开发一个猪八戒网站,大约需要多少?或者自己请程序员,需要什么程序员,多少程序员能完成?
C#怎么使用委托和事件 C# delegate与event编程方法
山东网站制作公司有哪些,山东大源集团官网?
如何选择高效稳定的ISP建站解决方案?
如何快速搭建虚拟主机网站?新手必看指南
如何选择网络建站服务器?高效建站必看指南
c# Task.ConfigureAwait(true) 在什么场景下是必须的
公众号网站制作网页,微信公众号怎么制作?
如何高效完成自助建站业务培训?
电影网站制作价格表,那些提供免费电影的网站,他们是怎么盈利的?
建站OpenVZ教程与优化策略:配置指南与性能提升
如何用景安虚拟主机手机版绑定域名建站?
c++23 std::expected怎么用 c++优雅处理函数错误返回【详解】
javascript中的try catch异常捕获机制用法分析
头像制作网站在线制作软件,dw网页背景图像怎么设置?
如何高效搭建专业期货交易平台网站?
如何快速完成中国万网建站详细流程?
如何在云虚拟主机上快速搭建个人网站?
广州网站设计制作一条龙,广州巨网网络科技有限公司是干什么的?
巅云智能建站系统:可视化拖拽+多端适配+免费模板一键生成
东莞市网站制作公司有哪些,东莞找工作用什么网站好?
c# F# 的 MailboxProcessor 和 C# 的 Actor 模型
如何高效配置香港服务器实现快速建站?
,制作一个手机app网站要多少钱?
三星网站视频制作教程下载,三星w23网页如何全屏?
详解ASP.NET 生成二维码实例(采用ThoughtWorks.QRCode和QrCode.Net两种方式)
如何设计高效校园网站?
如何获取PHP WAP自助建站系统源码?
用v-html解决Vue.js渲染中html标签不被解析的问题
香港服务器建站指南:免备案优势与SEO优化技巧全解析
黑客如何通过漏洞一步步攻陷网站服务器?
如何在Golang中实现微服务服务拆分_Golang微服务拆分与接口管理方法
英语简历制作免费网站推荐,如何将简历翻译成英文?
北京企业网站设计制作公司,北京铁路集团官方网站?
网站制作知乎推荐,想做自己的网站用什么工具比较好?
制作网站的软件下载免费,今日头条开宝箱老是需要下载怎么回事?
专业的网站制作设计是什么,如何制作一个企业网站,建设网站的基本步骤有哪些?
如何设置并定期更换建站之星安全管理员密码?
*请认真填写需求信息,我们会在24小时内与您取得联系。