配置BeautifulSoup4+lxml+html5lib
序
Windows平台 + Python3.5
安装BeautifulSoup4
安装html5lib
安装lxml
Lxml, a binding for the libxml2 and libxslt libraries.
lxml‑3.4.4‑cp27‑none‑win32.whl
lxml‑3.4.4‑cp27‑none‑win_amd64.whl
lxml‑3.4.4‑cp33‑none‑win32.whl
lxml‑3.4.4‑cp33‑none‑win_amd64.whl
lxml‑3.4.4‑cp34‑none‑win32.whl
lxml‑3.4.4‑cp34‑none‑win_amd64.whl
lxml‑3.4.4‑cp35‑none‑win32.whl
lxml‑3.4.4‑cp35‑none‑win_amd64.whl
cp后面是Python的版本号,27表示2.7,根据你的Python版本选择下载。
- pip install BeautifulSoup4 或 easy_install BeautifulSoup4
- pip install html5lib
- pip install lxml
使用BeautifulSoup
- html = """
- <html><head><title>The Dormouse's story</title></head>
- <body>
- <p class="title"><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="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>
- """
- from bs4 import BeautifulSoup
- #添加一个解析器
- soup = BeautifulSoup(html,'html5lib')
- print(soup.title)
- print(soup.title.name)
- print(soup.title.text)
- print(soup.body)
- #从文档中找到所有<a>标签的内容
- for link in soup.find_all('a'):
- print(link.get('href'))
- #从文档中找到所有文字内容
- print(soup.get_text())
注意:
配置BeautifulSoup4+lxml+html5lib的更多相关文章
- Python爬虫beautifulsoup4常用的解析方法总结
摘要 如何用beautifulsoup4解析各种情况的网页 beautifulsoup4的使用 关于beautifulsoup4,官网已经讲的很详细了,我这里就把一些常用的解析方法做个总结,方便查阅. ...
- Python爬虫beautifulsoup4常用的解析方法总结(新手必看)
今天小编就为大家分享一篇关于Python爬虫beautifulsoup4常用的解析方法总结,小编觉得内容挺不错的,现在分享给大家,具有很好的参考价值,需要的朋友一起跟随小编来看看吧摘要 如何用beau ...
- 爬虫基础以及 re,BeatifulSoup,requests模块使用
爬虫基础以及BeatifulSoup模块使用 爬虫的定义:向网站发起请求,获取资源后分析并提取有用数据的程序 爬虫的流程 发送请求 ---> request 获取响应内容 ---> res ...
- 【学习笔记】PYTHON网络爬虫与信息提取(北理工 嵩天)
学习目的:掌握定向网络数据爬取和网页解析的基本能力the Website is the API- 1 python ide 文本ide:IDLE,Sublime Text集成ide:Pychar ...
- Python网络爬虫与信息提取笔记
直接复制粘贴笔记发现有问题 文档下载地址//download.csdn.net/download/hide_on_rush/12266493 掌握定向网络数据爬取和网页解析的基本能力常用的 Pytho ...
- 1 python大数据挖掘系列之基础知识入门
preface Python在大数据行业非常火爆近两年,as a pythonic,所以也得涉足下大数据分析,下面就聊聊它们. Python数据分析与挖掘技术概述 所谓数据分析,即对已知的数据进行分析 ...
- 转:Beautiful Soup
Beautiful Soup 是一个可以从HTML或XML文件中提取数据的Python库.它能够通过你喜欢的转换器实现惯用的文档导航,查找,修改文档的方式.Beautiful Soup会帮你节省数小时 ...
- 【bs4】安装beautifulsoup
Debian/Ubuntu,install $ apt-get install python-bs4 easy_install/pip $ easy_install beautifulsoup4 $ ...
- requests和BeautifulSoup
一:Requests库 Requests is an elegant and simple HTTP library for Python, built for human beings. 1.安装 ...
随机推荐
- Qt布局
常用的布局方法 1. 水平布局类 QHBoxLayout 2. 垂直布局类 QVBoxLayout 3. 网格布局类 QGridLayout QHBoxLayout 对象横向排列开 QVBoxLayo ...
- Qt QPushButton 背景色
正常状态:黑底(背景色),白字(前景色),圆角,向外凸起 鼠标停留:背景和前景反色 鼠标按下:背景色变为淡蓝色,向内凹陷 ui->pushButton->setStyleSheet(&qu ...
- web安全在线工具梳理
目录: (一)搜索引擎语法一.百度.国内二.bing(必应).微软的三.google.国外 (二)网络空间搜索引擎用于查找网络空间的目标设备一.撒旦.国外二.钟馗之眼.国内三.佛法.国内 (三)在线w ...
- jQuery基础知识1
jquery的概念 js query jquery库 封装了大量js,封装js的入口函数.兼容性问题.DOM操作.事件.ajax 使用jquery 下载包 引用 <script src=&quo ...
- linux下解决find 1000/gfs无权限
用find查找根目录下的文件时,比如sudo find . -name \*test,就会出现1000/gfs无权限的情况 用一下方法可以正常使用 sudo find . -name test 2&g ...
- 搭建jenkins+python+selenium+robot framework环境
1.安装jenkins 具体参考:https://www.cnblogs.com/dydxw/p/10538103.html 2.下载插件 我是为了方便,把有关python.selenium.robo ...
- RocketMQ的技术亮点
高性能 存储原理 零拷贝 数据结构与存储逻辑 刷盘策略 长轮询PULL RocketMQ的Consumer都是从Broker拉消息来消费,但是为了能做到实时收消息,RocketMQ使用长轮询方式,可以 ...
- 洛谷P2396 yyy loves Maths VII【状压dp】
题目:https://www.luogu.org/problemnew/show/P2396 题意:有n个数,每次选择一个表示走$a[i]$步,每个数只能选一次. 最多有两个厄运数字,如果走到了厄运数 ...
- mybatis自测错题总结
试题分析:MyBatis有两种事务管理器类型是JDBC和MANAGED 试题分析:mybatis-config.xml文件使用用来编写影响mybatis行为的设置(settings) 和属性(pe ...
- PHP读取文件内容的方法
下面我们就为大家详细介绍PHP读取文件内容的两种方法. 第一种方法:fread函数 <?php $file=fopen('1.txt','rb+'); echo fread($file,file ...