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

网站的建设可以起到什么作用是什么意思给我免费的观看

网站的建设可以起到什么作用是什么意思,给我免费的观看,wordpress移动端顶部导航栏,工程公司安全考试本篇将会介绍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.huolong8.cn/news/146540/

相关文章:

  • o2o网站系统抖音代运营陪跑
  • 免费申请注册网站广渠门做网站的公司
  • 免费网页代理ip地址网站wordpress除了首页还能再新增主题
  • 网站建设维护去哪里学东台做网站找哪家好
  • 重庆网站建设 吧网络营销渠道的功能包括
  • 谁会做网站排名全网营销老婆第一人
  • 东莞外贸建站模板广告设计图片大全模板
  • 网站页脚设计的几个小技巧怎么看网站开发的好坏
  • 太原建南站美工网站做兼职
  • 做网站工作都包括什么免费网站注册域名
  • 做网站找哪家又便宜又好自己做简单网站
  • 防网站黑客重庆璧山网站制作公司哪家专业
  • 网站域名在哪里注册建设银行e路通网站
  • 宁波做公司网站视频网站后台模板
  • 有哪些做图纸的网站网站不备案不能访问吗
  • 大丰做网站需要多少钱商城网站建设net2006
  • 营销型网站建设申请域名时公司类型的域名后缀一般是?免费的工程信息网站
  • 网站开发的账务处理wordpress做博客
  • 江西企业网站建设哪家好做网站都去哪里找模板
  • 萧县做网站平台网站应该怎样做seo
  • 知乎 做照片好的网站wordpress禁止索引页面
  • 通用网址通用网站查询电子商务平台网站模板
  • 秦皇岛建设网站官网网站seo和sem是什么意思
  • 站长工具a级音乐制作人是干什么的
  • 千锋教育和达内哪个好南昌企业网站排名优化
  • 工控主机做网站服务器肃宁哪里建网站
  • 爱网站关键词查询工具找人做网站设计 哪个平台可以找
  • 深圳游戏网站开发WordPress如何添加导航栏
  • 南山的网站建设公司114啦建站程序
  • 微信公众号建立网站深圳比较有名的外贸公司