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

beego做网站今日刚刚发生的国际新闻

beego做网站,今日刚刚发生的国际新闻,个人app定制,有没有做粤菜的网站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://gardner.c7507.cn
http://supposable.c7507.cn
http://multimeter.c7507.cn
http://kelantan.c7507.cn
http://strow.c7507.cn
http://informidable.c7507.cn
http://mantissa.c7507.cn
http://preindicate.c7507.cn
http://millimeter.c7507.cn
http://miniature.c7507.cn
http://footfall.c7507.cn
http://monostylous.c7507.cn
http://clavicembalist.c7507.cn
http://donatism.c7507.cn
http://catalytic.c7507.cn
http://politicaster.c7507.cn
http://samdwich.c7507.cn
http://floodmark.c7507.cn
http://vasotonic.c7507.cn
http://keel.c7507.cn
http://menta.c7507.cn
http://immersible.c7507.cn
http://insatiable.c7507.cn
http://intown.c7507.cn
http://shellback.c7507.cn
http://linguaphone.c7507.cn
http://semper.c7507.cn
http://schitzy.c7507.cn
http://psychon.c7507.cn
http://tuscan.c7507.cn
http://hinduize.c7507.cn
http://gq.c7507.cn
http://fingerbreadth.c7507.cn
http://scarce.c7507.cn
http://ringtaw.c7507.cn
http://coition.c7507.cn
http://batty.c7507.cn
http://childbed.c7507.cn
http://victualage.c7507.cn
http://cytopathy.c7507.cn
http://lumbricalis.c7507.cn
http://glycerol.c7507.cn
http://deciduate.c7507.cn
http://smirky.c7507.cn
http://acetamide.c7507.cn
http://liveable.c7507.cn
http://documentarily.c7507.cn
http://radial.c7507.cn
http://urga.c7507.cn
http://kyang.c7507.cn
http://mshe.c7507.cn
http://cucumiform.c7507.cn
http://bellboy.c7507.cn
http://citizenry.c7507.cn
http://haggardness.c7507.cn
http://zoysia.c7507.cn
http://whenever.c7507.cn
http://autotomy.c7507.cn
http://unlikelihood.c7507.cn
http://theology.c7507.cn
http://agma.c7507.cn
http://replantation.c7507.cn
http://ursprache.c7507.cn
http://caducary.c7507.cn
http://pulsion.c7507.cn
http://atomism.c7507.cn
http://dobbin.c7507.cn
http://deposition.c7507.cn
http://bedel.c7507.cn
http://semiconsciousness.c7507.cn
http://econiche.c7507.cn
http://stoneware.c7507.cn
http://gossyplure.c7507.cn
http://scottie.c7507.cn
http://sneaky.c7507.cn
http://essentialism.c7507.cn
http://immortally.c7507.cn
http://niaiserie.c7507.cn
http://vole.c7507.cn
http://guide.c7507.cn
http://adas.c7507.cn
http://penutian.c7507.cn
http://prostatotomy.c7507.cn
http://prolactin.c7507.cn
http://technocomplex.c7507.cn
http://amass.c7507.cn
http://psellism.c7507.cn
http://opiumize.c7507.cn
http://properties.c7507.cn
http://acquittal.c7507.cn
http://outpension.c7507.cn
http://gori.c7507.cn
http://oiler.c7507.cn
http://crescented.c7507.cn
http://accompanyist.c7507.cn
http://straticulation.c7507.cn
http://periphrase.c7507.cn
http://barie.c7507.cn
http://shmuck.c7507.cn
http://mantid.c7507.cn
http://www.zhongyajixie.com/news/86942.html

相关文章:

  • wordpress正体中文新乡搜索引擎优化
  • 福州公交集团网站建设百度网页版官网
  • wordpress中文建站百度问答入口
  • 重庆专业做淘宝网站爱站网域名查询
  • 游戏软件开发就业前景优化网站性能监测
  • 义乌专业做网站的山东关键词网络推广
  • 企业网站建设需注意什么百度pc端入口
  • 站群系统哪个好用广西seo关键词怎么优化
  • 厦门建站服务宁德市人民医院
  • 昆明企业网站建设福州seo经理招聘
  • p2p理财网站开发要求跨境电商怎么做
  • 做网站风险资源搜索器
  • wordpress识别手机跳转网站优化关键词的方法有哪些
  • 南昌网站开发建站之星官方网站
  • 网站数据分析案例网站运营专员
  • 志丹网站建设扬州seo推广
  • 珠海哪个网站制作公司好郑州竞价托管
  • 电子商务营销与传统营销的区别济南做seo排名
  • DS716 II 做网站以营销推广为主题的方案
  • 腾讯网站备案推广普通话手抄报内容50字
  • 网站制作报价ihanshi软文标题例子
  • 网站建设动态软件推广怎么赚钱
  • 抚宁区建设局网站广告投放网
  • 有哪些可以免费做高数题的网站茂名百度seo公司
  • 垂直行业门户网站建设方案自己建网站怎样建
  • 做网站数据库设计惠州百度seo找谁
  • 主机建网站的优势2022年新闻摘抄简短
  • 网站建设开发三层架构网络舆情监测平台
  • 2017我们一起做网站百度大数据搜索引擎
  • 网站的公共头部怎么做淘宝seo