BeautifulSoup_python3
1.错误排除
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
BeautifulSoup_python3的更多相关文章
随机推荐
- ubuntu下nginx+php5的部署
ubuntu下nginx+php5环境的部署和centos系统下的部署稍有不同,废话不多说,以下为操作记录:1)nginx安装root@ubuntutest01-KVM:~# sudo apt-get ...
- Web APP开发技巧总结
http://www.admin10000.com/document/6304.html 1. 当网站添加到主屏幕后再点击进行启动时,可隐藏地址栏(从浏览器跳转或输入链接进入并没有此效果) <m ...
- spring mvc总结1
1,spring下载 spring更改了官方网站后,找了很长时间没有找到相关的jar包下载路径,然后在网上终于找到相关的路径了 有个树形结构可供选择:http://repo.spring.io/rel ...
- 未在本地计算机上注册“microsoft.ACE.oledb.12.0”提供程序解决办法
一.未在本地计算机上注册“microsoft.ACE.oledb.4.0”提供程序 http://download.microsoft.com/download/7/0/3/703ffbcb-dc0c ...
- 简单创建与布署CLR存储过程
今天的博文是学习CLR存储过程,一个简单的例子,学会怎样创建,编译,布署在SQL中.CLR能做一些T-SQL无法做的事情,很多情况之后,它比T-SQL快. 打开VS2013,创建一个新专案,参考下面5 ...
- Spring Security笔记:使用BCrypt算法加密存储登录密码
在前一节使用数据库进行用户认证(form login using database)里,我们学习了如何把“登录帐号.密码”存储在db中,但是密码都是明文存储的,显然不太讲究.这一节将学习如何使用spr ...
- Linux文件结构及基本文件夹
虽然Linux系统有很多种类,但是对于文件系统分区这块,基本上各个版本的Linux系统都是一样的.Linux文件系统分区不像Windows那样将硬盘分为C.D.E.F盘这样,Linux的文件结构是单个 ...
- JavaScript数独求解器
<html> <head> <style type="text/css"> .txt { width: 50; height: 50; back ...
- Dll的显式和隐式调用
建立项目,请选择Win32 控制台项目(Win32 Console Application),选择DLL和空项目选项.DLLs可能并不如你想像的那样难.首先写你的头文件(header file):称为 ...
- easyui添加生成tab和子页面jsp
<!DOCTYPE html><html> <head> <meta charset="utf-8"> <title>& ...