BeautifulSoup_python3
2016-04-19 17:15
363 查看
1.错误排除
报错:
解决办法:
python3 安装 版本4 BeautifulSoup4 (BS4)
运行实例:
第12 行注意,需要加上 "html.parser"
结果:
官方文档
bsObj = BeautifulSoup(html.read())
报错:
UserWarning: No parser was explicitly specified, so I'm using the best available HTML parser for this system ("lxml"). This usually isn't a problem, but if you run this code on another system, or in a different virtual environment, it may use a different parser and behave differently.
解决办法:
bsObj = BeautifulSoup(html.read(),"html.parser")
BeautifulSoup
简介:通过定位HTML标签来格式化和组织复杂的网络信息,用简单的python对象来展现XML结构信息。python3 安装 版本4 BeautifulSoup4 (BS4)
运行实例:
#!/usr/bin/env python # encoding: utf-8 """ @author: 侠之大者kamil @file: beautifulsoup.py @time: 2016/4/19 16:36 """ from bs4 import BeautifulSoup from urllib.request import urlopen html = urlopen('http://www.cnblogs.com/kamil/') print(type(html)) bsObj = BeautifulSoup(html.read(),"html.parser") #html.read() 获取网页内容,并且传输到BeautifulSoup 对象。 print(type(bsObj)) print(bsObj.h1)
第12 行注意,需要加上 "html.parser"
结果:
ssh://kamil@xzdz.hk:22/usr/bin/python3 -u /home/kamil/windows_python3/python3/Day11/day12/beautifulsoup.py <class 'http.client.HTTPResponse'> <class 'bs4.BeautifulSoup'> <h1><a class="headermaintitle" href="http://www.cnblogs.com/kamil/" id="Header1_HeaderTitle">侠之大者kamil</a></h1> Process finished with exit code 0
官方文档
相关文章推荐
- 用python进行科学统计及数据挖掘--便捷工具环境搭建
- python2 与 python3 语法区别
- python @ property classmethod staticmethod
- 机器学习系列(9)_机器学习算法一览(附Python和R代码)
- python 爬虫 beautifulsoup example 例子
- 机器学习算法笔记系列之深入理解主成分分析PCA-Python实现篇
- Mac 安装 Scrapy
- wxPython 图形界面程序时 多个显示器问题。
- Python中关于封装,继承,多态的表述
- python3时间处理
- Python 解析配置模块之ConfigParser详解
- Python 编辑器 tips
- python 字典get方法
- Python学习(2)基本语法
- python学习笔记(pict+requests+xml)
- 【python小练】0017-将xls文件内容写入xml文件中
- Python学习笔记(九)
- python学习
- python 鸭子类型
- Python字符串的方法及注释