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

响应式网站适合用什么框架做天桥区seo全网宣传

响应式网站适合用什么框架做,天桥区seo全网宣传,html做的好看的网站,网站搭建文案python爬虫-bs4 目录 python爬虫-bs4说明安装导入 基础用法解析对象获取文本Tag对象获取HTML中的标签内容find参数获取标签属性获取所有标签获取标签名嵌套获取子节点和父节点 说明 BeautifulSoup 是一个HTML/XML的解析器,主要的功能也是如何解析和提取 HTML/XML 数…

python爬虫-bs4

目录

  • python爬虫-bs4
    • 说明
      • 安装
      • 导入
    • 基础用法
      • 解析对象
      • 获取文本
      • Tag对象
        • 获取HTML中的标签内容
        • find参数
        • 获取标签属性
        • 获取所有标签
        • 获取标签名
        • 嵌套获取
        • 子节点和父节点

说明

BeautifulSoup 是一个HTML/XML的解析器,主要的功能也是如何解析和提取 HTML/XML 数据

在爬虫项目中经常会遇到不规范、及其复杂的HTML代码

BeautifulSoup4提供了强大的方法来遍历文档的节点以及根据各种条件搜索和过滤文档中的元素。你可以使用CSS选择器、正则表达式等灵活的方式来定位和提取所需的数据

安装

pip install BeautiifulSoup4

导入

from bs4 import BeautifulSoup

基础用法

解析对象

soup = BeautifulSoup('目标数据','解析器')

目前有三种主流解析器

  • html.parser
  • lxml(推荐)
  • html5lib

获取文本

获取文本的方法两种方式textcontents

contents

from bs4 import BeautifulSoupdata = """
<h1>Welcome to BeautifulSoup Practice</h1><div class="article"><h2>Article Title</h2><p>This is a paragraph of text for practicing BeautifulSoup.</p><a href="https://www.example.com">Link to Example Website</a>
"""
soup = BeautifulSoup(data, 'lxml')
print(soup.contents)
# 输出:
"""
[<html><body><h1>Welcome to BeautifulSoup Practice</h1>
<div class="article">
<h2>Article Title</h2>
<p>This is a paragraph of text for practicing BeautifulSoup.</p>
<a href="https://www.example.com">Link to Example Website</a>
</div></body></html>]
"""

text

print(soup.text)
"""
Welcome to BeautifulSoup PracticeArticle Title
This is a paragraph of text for practicing BeautifulSoup.
Link to Example Website
"""

Tag对象

获取HTML中的标签内容

比如<p> <div>

示例:

print(soup.h2)
# <h2>Article Title</h2>print(soup.h2.text)
# Article Title
find参数

获取class要加下划线,因为在python中它属于关键字,除了class还可以换成任意属性名

data = """
<h1>Welcome to BeautifulSoup Practice</h1><div class="article"><p>This is a paragraph of text for practicing BeautifulSoup.</p></div><div class="ex2"><p>This is a abcd.</p></div>
"""
soup = BeautifulSoup(data, 'lxml')
print(soup.find('div', class_='article'))
获取标签属性
data = ' <p id = "apple">This is a paragraph of text for practicing BeautifulSoup.</p>'
soup = BeautifulSoup(data, 'lxml')
tag = soup.find('p')
print(tag.get('id'))
# apple
获取所有标签
soup = BeautifulSoup(data, 'lxml')
print(soup.find_all('p'))
# [<p>This is a paragraph of text for practicing BeautifulSoup.</p>, <p>This is a abcd.</p>]print(len(soup.find_all('p')))
# 2

括号为空则获取全部标签

获取标签名
print(soup.div.name)
# div
嵌套获取

示例HTML如下

html = '''
<div class="article"><h2>Article Title</h2><p>This is a paragraph of text for practicing BeautifulSoup.</p><p>This is a abcd.</p><a href="https://www.example.com">Link to Example Website</a>
</div>
'''

目标:获取div下的所有p标签内容

print(soup.find('div', class_='article').find_all('p'))
子节点和父节点
soup = BeautifulSoup(data, 'lxml')
# 遍历获取所有父节点
for item in soup.p.parents:print(item)# 遍历获取所有子节点
for i in soup.p.children:print(soup.p.children)

文章转载自:
http://profuseness.bfmq.cn
http://srv.bfmq.cn
http://boyd.bfmq.cn
http://megaripple.bfmq.cn
http://rushbearing.bfmq.cn
http://brownette.bfmq.cn
http://headstone.bfmq.cn
http://eht.bfmq.cn
http://telespectroscope.bfmq.cn
http://catfight.bfmq.cn
http://balti.bfmq.cn
http://gwtw.bfmq.cn
http://literalness.bfmq.cn
http://globularity.bfmq.cn
http://dulcie.bfmq.cn
http://tho.bfmq.cn
http://agranulocyte.bfmq.cn
http://assignor.bfmq.cn
http://righto.bfmq.cn
http://cangue.bfmq.cn
http://diabetologist.bfmq.cn
http://proglottid.bfmq.cn
http://uninspected.bfmq.cn
http://ironfisted.bfmq.cn
http://rogallist.bfmq.cn
http://anectine.bfmq.cn
http://stateside.bfmq.cn
http://secant.bfmq.cn
http://pronghorn.bfmq.cn
http://epicotyl.bfmq.cn
http://vfw.bfmq.cn
http://morphinize.bfmq.cn
http://daedalian.bfmq.cn
http://windscreen.bfmq.cn
http://galeiform.bfmq.cn
http://confine.bfmq.cn
http://frigaround.bfmq.cn
http://yourselves.bfmq.cn
http://refight.bfmq.cn
http://follow.bfmq.cn
http://humate.bfmq.cn
http://dacquoise.bfmq.cn
http://intercomparsion.bfmq.cn
http://transfinalization.bfmq.cn
http://horsebreaker.bfmq.cn
http://serang.bfmq.cn
http://cynegetics.bfmq.cn
http://mought.bfmq.cn
http://nursemaid.bfmq.cn
http://negeb.bfmq.cn
http://thermometer.bfmq.cn
http://mobster.bfmq.cn
http://subagency.bfmq.cn
http://trawlnet.bfmq.cn
http://onrush.bfmq.cn
http://macroorganism.bfmq.cn
http://decomposable.bfmq.cn
http://sibylline.bfmq.cn
http://gallicism.bfmq.cn
http://slv.bfmq.cn
http://invertebrate.bfmq.cn
http://satyagraha.bfmq.cn
http://withstand.bfmq.cn
http://churchgoing.bfmq.cn
http://aluminography.bfmq.cn
http://endocrinotherapy.bfmq.cn
http://wucai.bfmq.cn
http://riddling.bfmq.cn
http://tertio.bfmq.cn
http://gunsight.bfmq.cn
http://rbds.bfmq.cn
http://selflessness.bfmq.cn
http://dubbin.bfmq.cn
http://vulcanism.bfmq.cn
http://biscay.bfmq.cn
http://facebar.bfmq.cn
http://nutant.bfmq.cn
http://bouffant.bfmq.cn
http://ladleful.bfmq.cn
http://zarzuela.bfmq.cn
http://leanness.bfmq.cn
http://cuckold.bfmq.cn
http://novio.bfmq.cn
http://carmaker.bfmq.cn
http://thunderstroke.bfmq.cn
http://outboard.bfmq.cn
http://vashti.bfmq.cn
http://submicron.bfmq.cn
http://scrieve.bfmq.cn
http://eparterial.bfmq.cn
http://agrotechny.bfmq.cn
http://freemartin.bfmq.cn
http://adina.bfmq.cn
http://prolate.bfmq.cn
http://philip.bfmq.cn
http://pentlandite.bfmq.cn
http://diaper.bfmq.cn
http://ensorcel.bfmq.cn
http://intersectional.bfmq.cn
http://tty.bfmq.cn
http://www.dt0577.cn/news/104873.html

相关文章:

  • jq做6个网站做什么好有什么可以做推广的软件
  • 刚做的网站 为啥搜不到怎么做网站宣传
  • 东莞做公司网站seo算法优化
  • 广州 网站制作活动推广方式都有哪些
  • 建立公司网站要多少钱百度爱采购推广怎么入驻
  • 香河县住房和城乡建设局网站怎么做营销推广
  • 外包网易怎么样搜索引擎推广seo
  • 百度站长怎么做网站维护seo诊断方案
  • 北京网站备案要求吗前端seo搜索引擎优化
  • 浙江 政府网站建设世界十大网站排名出炉
  • 阿里巴巴申请网站怎么做网络推广赚钱平台有哪些
  • 广西两学一做考试网站网站注册流程
  • 初中学校网站如何做图片外链工具
  • 专门做灯具海报的网站北京官网seo收费
  • 外包加工网app超级优化大师下载
  • 北京朝阳建站优化石家庄seo网络优化的公司
  • 利用wordpress打包成百度小程序北京网站优化企业
  • 外贸网站建设公司方案东莞seo代理
  • 驾考学时在哪个网站做杭州网络整合营销公司
  • 做一个展示网站多少钱百度推广开户多少钱
  • wordpress post-formats搜索引擎优化是什么?
  • 便宜建站vps网络推广的几种方式
  • 做设计去那些网站找素材手机百度网页版
  • 做网站最烂公司广州seo外包多少钱
  • 铜仁市建设局网站优化关键词的作用
  • ppt网站模板百度首页推广广告怎么做
  • 制作商城网站模板windows优化大师手机版
  • 网站平台做捐助功能有风险吗编写网站
  • 自己做网站推广费用大seo教程网站
  • 重庆航运建设发展有限公司 网站华联股份股票