当前位置: 首页 > news >正文

beego做网站百度爱采购官网首页

beego做网站,百度爱采购官网首页,人社部回应:一建一造停,自己做一个appBeautiful Soup 网页解析库的使用 文章目录 Beautiful Soup 网页解析库的使用前言一、安装Beautiful Soup 和 lxml二、Beautiful Soup基本使用方法标签选择器1 .string --获取文本内容2 .name --获取标签本身名称3 .attrs[] --通过属性拿属性的值标准选择器find_all( name , at…

Beautiful Soup 网页解析库的使用

文章目录

  • Beautiful Soup 网页解析库的使用
  • 前言
  • 一、安装Beautiful Soup 和 lxml
  • 二、Beautiful Soup基本使用方法
    • 标签选择器
      • 1 .string --获取文本内容
      • 2 .name --获取标签本身名称
      • 3 .attrs[] --通过属性拿属性的值
    • 标准选择器
      • find_all( name , attrs , recursive , text , **kwargs )
        • text=() 根据文本值选择
      • find( name , attrs , recursive , text , **kwargs )
    • CSS选择器
      • 获取属性的值
  • 总结


前言

大家好,今天我们来说一说爬虫中比较常用的一种解析数据的网页解析库—Beautiful Soup 的使用.可以从html网页中提取出我们想要的数据,比re正则方便而且还不容易出错,所以是爬虫中的得力助手.

beautiful soup支持多种解析器 例如’XML’ .‘HTML’ 等等

以下是beautiful soup所支持的解析器

在这里插入图片描述


一、安装Beautiful Soup 和 lxml

win + r 输入cmd 在终端中输入: pip install BeautifulSoup4 再输入 pip install lxml

注意: 如果出现爆红 或者警告 尝试使用镜像源下载 (以前的文章说过)


二、Beautiful Soup基本使用方法

标签选择器

1 .string --获取文本内容

h = """
<html><head><title>The Dormouse's story</title></head><body><p class="title" name="dromouse"><b><span>The Dormouse's story</span></b></p><p class="story">Once upon a time there were three little sisters; and their names were<a href="http://example.com/elsie" class="sister" id="link1"><!-- Elsie --></a>,<a href="http://example.com/lacie" class="sister" id="link2">Lacie</a> and<a href="http://example.com/tillie" class="sister" id="link3">Tillie</a>;and they lived at the bottom of a well.</p><p class="story">...</p>
"""# 1,导包
from bs4 import BeautifulSoup 
#,2,实例化对象
soup = BeautifulSoup(h, 'lxml')  # 参数1:要解析的内容  参数2:解析器# 通过标签选取,会返回包含标签本身及其里面的所有内容
print(soup.head) # 包含head标签在内的所有内容
print(soup.p) # 返回匹配的第一个结果# .string是属性,作用是获取字符串文本
print(soup.title.string)

运行结果:

	<head><title>The Dormouse's story</title></head><p class="title" name="dromouse"><b><span>The Dormouse's story</span></b></p>The Dormouse's story

2 .name --获取标签本身名称

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" class="sister" id="link1"><!-- Elsie --></a>,
<a href="http://example.com/lacie" class="siste
http://www.ritt.cn/news/22745.html

相关文章:

  • 商城网站 运营世界新闻
  • 怎么区分营销型和展示型的网站腾讯广告官网
  • wordpress主题ftpseo顾问是什么职业
  • wordpress中文建站搜索引擎网址
  • 沈阳企业建站网站建设总结
  • 浙江省住房和城乡建设厅官方网站营销策略有哪些
  • php在网站开发中的作用免费单页网站在线制作
  • 顺德公益网站制作网络优化
  • 网站建设合同规范厦门关键词优化平台
  • 中学网站建设软文广告发稿
  • 一般设计网站页面用什么软件查排名网站
  • 建立企业网站的好处网络营销未来有哪些发展趋势
  • c语言哪个网站可以做测试题百度app浏览器下载
  • 制作网站电话百度手机软件应用中心
  • 中国建设银行潍坊市分行官方网站域名服务器查询
  • ckplayer怎么上传做网站洛阳市网站建设
  • 网站建设测试事业运程网络软文怎么写
  • 浅谈wordpress接入熊掌号长沙正规竞价优化服务
  • 嘉祥网站建设多少钱学seo需要多久
  • 一个网站的建设要经过哪几个阶段今日新闻头条内容
  • wordpress调试seo优化服务价格
  • 客户网站回访陕西网站seo
  • 舟山网站建设优化今日实时热搜
  • 昆山网站建设 技术支持 力得网络网络营销策划创意案例点评
  • 个人域名备案要求网站seo优化外包
  • 滴滴出行的网站是哪家公司做的线上推广方案模板
  • 网站开发wbs案例建网站需要什么条件
  • 微信微网站是什么微信加精准客源软件
  • 怎么自己做网站怎么赚钱优化seo深圳
  • 瓷砖网站建设网站优化推广外包