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

网站开发 招聘wordpress 编辑自己代码

网站开发 招聘,wordpress 编辑自己代码,在线设计网名生成器,湛江建站价格Beautiful 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.yayakq.cn/news/898709/

相关文章:

  • 北京模板建站软件免费的网站入口在哪
  • 网站建设与运行的盈利收入wordpress输出响应式图片大小
  • 宁波网站建设最好的是哪家html5软件官方下载
  • php做投票网站定制公众号需要多少钱
  • 化妆品品牌网站建设wordpress 嵌入
  • 模板网站建设优惠专家一对一免费咨询
  • 天津建设银行公积金缴费官方网站工程软件开发
  • 山西网站建设推荐高明网站设计服务
  • 清河企业做网站中文wordpress主题推荐
  • 网站排名英文在网站建设工作会议上讲话
  • 怎么做网站流量赚钱建设银行官方网站网址
  • 彩票销信 网站怎么做浏览器主页网址推荐
  • 一个网站要怎么做wordpress多账号权限
  • 企业网站建设性能分析城市网站建设意义
  • 商事制度改革对网站建设的要求wordpress 加ico
  • 深圳建站推广公司wordpress 头部修改
  • 建站公司怎么拓客部门网站开发
  • 网络网站是多少钱一年重庆中色十二冶金建设有限公司网站
  • 欧美 电台 网站模板泊头网站建设公司
  • wordpress整站克隆qq是哪个公司
  • 安徽网站建设外贸广东广州番禺区
  • 安徽建设厅网站证件查询网站开发项目企划书
  • 网站建设意识形态工作php网站开发框架有哪些
  • 廊坊网络推广建站哪个网站可以领手工回家做
  • 无锡建设网站40个免费网站推广平台
  • 为什么自己做不出一个好网站室内装修效果图网站有哪些
  • 成都高端网站建设那家好快速排名优化
  • 做棋牌网站要什么源码企业网站建设的策划书
  • 免费制作网络商城网站征婚网站怎么做
  • 织梦的网站模板免费吗wordpress插件关闭更新