前言

本文主要介绍的是关于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
相关文章:
怎么制作网站设计模板图片,有电商商品详情页面的免费模板素材网站推荐吗?
如何快速查询网站的真实建站时间?
html制作网站的步骤有哪些,iapp如何添加网页?
如何选择香港主机高效搭建外贸独立站?
官网建站费用明细查询_企业建站套餐价格及收费标准指南
学校为何禁止电信移动建设网站?
详解ASP.NET 生成二维码实例(采用ThoughtWorks.QRCode和QrCode.Net两种方式)
建站之星导航配置指南:自助建站与SEO优化全解析
建站三合一如何选?哪家性价比更高?
如何选择CMS系统实现快速建站与SEO优化?
关于BootStrap modal 在IOS9中不能弹出的解决方法(IOS 9 bootstrap modal ios 9 noticework)
建站之星后台管理:高效配置与模板优化提升用户体验
平台云上自助建站如何快速打造专业网站?
建站主机功能解析:服务器选择与快速搭建指南
香港服务器WordPress建站指南:SEO优化与高效部署策略
如何在IIS管理器中快速创建并配置网站?
如何通过网站建站时间优化SEO与用户体验?
广州商城建站系统开发成本与周期如何控制?
如何在阿里云完成域名注册与建站?
如何在景安云服务器上绑定域名并配置虚拟主机?
小自动建站系统:AI智能生成+拖拽模板,多端适配一键搭建
C++如何将C风格字符串(char*)转换为std::string?(代码示例)
免费的流程图制作网站有哪些,2025年教师初级职称申报网上流程?
如何选择网络建站服务器?高效建站必看指南
建站主机是否等同于虚拟主机?
如何快速生成ASP一键建站模板并优化安全性?
香港服务器部署网站为何提示未备案?
IOS倒计时设置UIButton标题title的抖动问题
公司网站的制作公司,企业网站制作基本流程有哪些?
深入理解Android中的xmlns:tools属性
公司门户网站制作流程,华为官网怎么做?
个人网站制作流程图片大全,个人网站如何注销?
C++时间戳转换成日期时间的步骤和示例代码
c# 在高并发场景下,委托和接口调用的性能对比
SQL查询语句优化的实用方法总结
内网网站制作软件,内网的网站如何发布到外网?
Java解压缩zip - 解压缩多个文件或文件夹实例
婚礼视频制作网站,学习*后期制作的网站有哪些?
北京制作网站的公司,北京铁路集团官方网站?
建站之星会员如何解锁更多建站功能?
香港服务器租用每月最低只需15元?
如何在IIS中新建站点并解决端口绑定冲突?
建站主机选虚拟主机还是云服务器更好?
网站好制作吗知乎,网站开发好学吗?有什么技巧?
如何在建站之星网店版论坛获取技术支持?
宁波免费建站如何选择可靠模板与平台?
建站之星伪静态规则如何正确配置?
,网站推广常用方法?
建站主机SSH密钥生成步骤及常见问题解答?
韩国服务器如何优化跨境访问实现高效连接?
*请认真填写需求信息,我们会在24小时内与您取得联系。