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

有没有什么做统计的网站公司网站建设框架

有没有什么做统计的网站,公司网站建设框架,企业推广软件有哪些,阿里指数查询官网在Python的网络爬虫中#xff0c;BeautifulSoup库是一个重要的网页解析工具。在初级教程中#xff0c;我们已经了解了BeautifulSoup库的基本使用方法。在本篇文章中#xff0c;我们将深入学习BeautifulSoup库的进阶使用。 一、复杂的查找条件 在使用find和find_all方法查找…在Python的网络爬虫中BeautifulSoup库是一个重要的网页解析工具。在初级教程中我们已经了解了BeautifulSoup库的基本使用方法。在本篇文章中我们将深入学习BeautifulSoup库的进阶使用。 一、复杂的查找条件 在使用find和find_all方法查找元素时我们可以使用复杂的查找条件例如我们可以查找所有class为story的p标签 from bs4 import BeautifulSouphtml_doc htmlheadtitleThe Dormouses story/title/head body p classtitlebThe Dormouses story/b/p p classstoryOnce upon a time there were three little sisters; and their names were/p soup BeautifulSoup(html_doc, html.parser)story_p_tags soup.find_all(p, class_story)for p in story_p_tags:print(p.string)二、遍历DOM树 在BeautifulSoup中我们可以方便的遍历DOM树以下是一些常用的遍历方法 from bs4 import BeautifulSouphtml_doc htmlheadtitleThe Dormouses story/title/head body p classtitlebThe Dormouses story/b/p p classstoryOnce upon a time there were three little sisters; and their names were/p soup BeautifulSoup(html_doc, html.parser)# 获取直接子节点 for child in soup.body.children:print(child)# 获取所有子孙节点 for descendant in soup.body.descendants:print(descendant)# 获取兄弟节点 for sibling in soup.p.next_siblings:print(sibling)# 获取父节点 print(soup.p.parent)三、修改DOM树 除了遍历DOM树我们还可以修改DOM树例如我们可以修改tag的内容和属性 from bs4 import BeautifulSouphtml_doc htmlheadtitleThe Dormouses story/title/head body p classtitlebThe Dormouses story/b/p p classstoryOnce upon a time there were three little sisters; and their names were/p soup BeautifulSoup(html_doc, html.parser)soup.p.string New story soup.p[class] new_titleprint(soup.p)四、解析XML 除了解析HTML外BeautifulSoup还可以解析XML我们只需要在创建BeautifulSoup对象时指定解析器为lxml-xml即可 from bs4 import BeautifulSoupxml_doc bookstore book categoryCOOKINGtitle langenEveryday Italian/titleauthorGiada De Laurentiis/authoryear2005/year /book /bookstore soup BeautifulSoup(xml_doc, lxml-xml)print(soup.prettify())以上就是BeautifulSoup库的进阶使用方法通过本篇文章我们可以更好地使用BeautifulSoup库进行网页解析以便更有效地进行网络爬虫。
http://www.hkea.cn/news/14284795/

相关文章:

  • 重庆营销型网站随做的好类似建E网模型网站建设
  • 四川建设厅网站打不开做班级网站的详细计划书
  • 杨凌做网站网址wordpress主菜单设置
  • 静态网站开发软件网站空间一般有多大
  • discuz网站建设网站建设小江
  • 网站建设平台 三合一宁波中小企业网站制作
  • 湖州站内优化seo公司陕西手机网站建站
  • 网站设计论文总结百度优化培训
  • 我要学做网站seo交流博客
  • 网站后台打打开空白做特产网站的原因
  • 用软件做seo网站关键词推广域名可以免费注册吗
  • 建设项目竣工验收公示网站网站建设的基本步奏
  • 徐州做网站公司哪家好wordpress google ad
  • 重庆工程招标网站有哪些企业网站选择第三方还是自己做
  • 饰品网站模板wordpress怎么设置标签分类
  • 网站建设比赛方案接收外国电视卫星天线
  • 建站网址不安全怎么利用360域名做网站
  • 网站自动更新文章十大ui培训机构
  • 内容电商的网站如何做北京感染峰值已过
  • 网站开发后端用什么高端手机网站 制作公司
  • 长宁做网站价格重庆怎么自己做网站
  • 营销型网站建设的特色弹幕做的视频网站
  • 个性化网站定制做网站所用的技术
  • 证书兼职的人才网站恩施公司做网站
  • api网站制作关键词汇总
  • 淮安网站建设方案郑州恩恩网站建设
  • 建行信用卡网站深圳定制旗袍实体店
  • 网站建设v北京专业seo
  • 新建网站怎么想谷歌和百度提交网站在布局
  • 门户网站排版平潭城乡住房建设厅网站