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

郑州企业网站设计公司哪家好上海学网站建设

郑州企业网站设计公司哪家好,上海学网站建设,佛山网站推广市场,ui界面设计实例100例本篇将会介绍beutifulsoup4模块#xff0c;可以用于网络爬虫、解析HTML和XML#xff0c;对于没有接触过前端#xff0c;不了解HTML是如何工作的#xff0c;需要先解释一下什么事HTML。 1. HTML 网页中的各种布局等的背后都是非常简单的纯文本格式#xff0c;那种格式称为…本篇将会介绍beutifulsoup4模块可以用于网络爬虫、解析HTML和XML对于没有接触过前端不了解HTML是如何工作的需要先解释一下什么事HTML。 1. HTML 网页中的各种布局等的背后都是非常简单的纯文本格式那种格式称为HTML。 关于HTML不用刻意的去学习所谓的HTML就是一堆括起来的符合或单词不同的单词就是标签其对应了不同的作用。 如果在网络上进行通信获取网页实际上不会得到我们打开的网页的界面得到的就是html的代码而我们关心的可能就是HTML中的一部内容就需要对HTTML也就是字符串进行解析找出我们需要的部分。通过python的字符串来进行处理也是可行的但是考虑到处理的效率也有相应的开发的模块。 2. 安装bs4 pip install beutifulsoup4官网文档(中文版): https://www.crummy.com/software/BeautifulSoup/bs4/doc.zh/ 3. 使用BeautifulSoup解析HTML实例 使用的HTML代码如下来自于官方文档中的范例a、p均为标签 html_doc htmlheadtitleThe Dormouses story/title/head body p classtitlebThe Dormouses story/b/pp classstoryOnce upon a time there were three little sisters; and their names were a hrefhttp://example.com/elsie classsister idlink1Elsie/a, a hrefhttp://example.com/lacie classsister idlink2Lacie/a and a hrefhttp://example.com/tillie classsister idlink3Tillie/a; and they lived at the bottom of a well./pp classstory.../p将其拷贝到一个txt文件改后缀为html利用浏览器打开就是一个网页如下 bs4中提供了BeautifulSoup的方法它可以将html字符串转化为一个soup对象。soup对象中提供了各种属性方法对应了htm文档使得我们可以很方便地提取相关信息 以下演示如何进行安装、导入模块、进行HTML的缩进美化 C:\Users\pip install beautifulsoup4 C:\Users\ipython In [1]: from bs4 import BeautifulSoup In [2]: html_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...: a hrefhttp://example.com/elsie classsister idlink1Elsie/a,...: a hrefhttp://example.com/lacie classsister idlink2Lacie/a and...: a hrefhttp://example.com/tillie classsister idlink3Tillie/a;...: and they lived at the bottom of a well./p...:...: p classstory.../p...: In [3]: soup BeautifulSoup(html_doc, html.parser) #转变为soup对象In [4]: print(soup.prettify()) #把原有HTML源码进行缩进美化 htmlheadtitleThe Dormouses story/title/headbodyp classtitlebThe Dormouses story/b/pp classstoryOnce upon a time there were three little sisters; and their names werea classsister hrefhttp://example.com/elsie idlink1Elsie/a,a classsister hrefhttp://example.com/lacie idlink2Lacie/aanda classsister hrefhttp://example.com/tillie idlink3Tillie/a; and they lived at the bottom of a well./pp classstory.../p/body /html 构造得到的soup对象中提供了各种操作的方法。 find_all找到所有的标签返回一个listlist中的每个元素是标签对象。 In [5]: soup.find_all(a) Out[5]: [a classsister hrefhttp://example.com/elsie idlink1Elsie/a,a classsister hrefhttp://example.com/lacie idlink2Lacie/a,a classsister hrefhttp://example.com/tillie idlink3Tillie/a]In [6]: for i in soup.find_all(a):...: print(i)...: a classsister hrefhttp://example.com/elsie idlink1Elsie/a a classsister hrefhttp://example.com/lacie idlink2Lacie/a a classsister hrefhttp://example.com/tillie idlink3Tillie/aIn [7]: mylist soup.find_all(a)In [8]: tag0 mylist[0]In [9]: tag0 Out[9]: a classsister hrefhttp://example.com/elsie idlink1Elsie/aIn [10]: tag0[href] #标签类似dict的封装得到href的value Out[10]: http://example.com/elsie In [11]: for item in mylist:...: print(item[href])...: http://example.com/elsie http://example.com/lacie http://example.com/tillie 4.学习视频地址使用python解析网页HTML
http://www.sczhlp.com/news/160091/

相关文章:

  • 建设网站公司简介安徽优化推广
  • vs做网站如何调试教育局网站建设方案
  • 重庆建设企业网站外贸网站建设推广公司前景如何
  • dw网页版seo视频教程百度云
  • 网站建设需求分析表怎么写项目商业网站建设方案
  • 公司网站怎样维护运营煎蛋网 wordpress
  • 网站登录注册怎么做搭建简单的网站
  • 切图做网站谷歌广告投放步骤
  • 招聘网站建设工作汇报兼职做彩平网站
  • 做舞台灯光的在哪些网站接订单呢番禺人才市场档案中心
  • 医疗设备厂家不要再盲选了,专业的医疗DMS经销商管理软件来了!
  • 2025年防撞软包厂家TOP企业品牌推荐排行榜,谈话室,留置病房,教育中心,体育馆,约谈室,监察机构,墙体,阻燃,醒酒室,墙面,洽谈室,留置室,防撞软包洽谈桌公司推荐
  • 2025年防撞软包厂家TOP企业品牌推荐排行榜,询问室,幼儿园,B1墙板,防撞软包门防火墙板,阻燃墙板,防撞软包家具,桌椅,马桶,洗手盆公司推荐
  • HTTP 错误 403.14 - Forbidden Web 服务器被配置为不列出此目录的内容——错误代码:0x00000000 - 教程
  • 许昌建设企业网站网店页面设计
  • 企业法律平台网站建设方案成都公司网页制作服务电话
  • 上饶市网站建设公司吉林房地产网站开发
  • app设计网站模板工作做网站
  • wordpress怎么做网站建站都需要什么
  • 汽车网站有哪些朗朗上口的广告公司名称
  • 个人网站建设 开题报告企业网站建设的必要性和重要性
  • 深圳网站建设公司专业自由策划网站建设
  • 东莞市公司网站建设平台基层组织建设部 网站
  • 教育品牌加盟网站建设重庆网站建设电脑版
  • 山东企业建站系统费用华为网站建设招聘
  • 江门自助建站模板娱乐网站后缀是什么
  • 做涂鸦的网站在线定制头像免费
  • 天宁常州做网站网站外链建设原则
  • dreamware做网站首页学生作业网站
  • 网站建设费用如何做账务处理浏阳建设局网站