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)

运行实例:

 1 #!/usr/bin/env python
 2 # encoding: utf-8
 3 """
 4 @author: 侠之大者kamil
 5 @file: beautifulsoup.py
 6 @time: 2016/4/19 16:36
 7 """
 8 from bs4 import BeautifulSoup
 9 from urllib.request import urlopen
10 html = urlopen('http://www.cnblogs.com/kamil/')
11 print(type(html))
12 bsObj = BeautifulSoup(html.read(),"html.parser") #html.read() 获取网页内容,并且传输到BeautifulSoup 对象。
13 print(type(bsObj))
14 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

官方文档

转载于:https://www.cnblogs.com/kamil/p/5408986.html

BeautifulSoup_python3相关推荐

  1. python3 beautifulsoup_Python3中BeautifulSoup的使用方法

    原标题:Python3中BeautifulSoup的使用方法

  2. python beautifulsoup_Python3 安装Beautifulsoup

    Python3 安装Beautifulsoup admin • 2019 年 11 月 22 日 [title]Beautifulsoup介绍[/title] HTML 文档本身是结构化的文本,有一定 ...

最新文章

  1. wp 删除独立存储空间文件(多级非空文件夹删除)
  2. 网站开启https后很慢_HTTPS会影响网站打开速度吗
  3. pythonweb毕业设计-[分享]我发现了一个快速完成物联网毕业设计的好方法!
  4. DrawerLayout
  5. 看看比尔·盖茨在关注什么
  6. awk的sub函数和gsub函数的用法
  7. ASP.NET知识集
  8. ORACLE连接数据库(备忘)
  9. Swagger自动接口文档生成框架————springboot整合swagger总结
  10. python圣诞树编写实例详解
  11. 【Flink】FlinkException The file LOG does not exist on the TaskExecutor
  12. php的核心类 控制,phpMVC框架的核心启动类定义
  13. 揭秘315黑客wifi,如何保障APP数据安全
  14. ERD-ONLINE 免费在线数据库建模工具
  15. windows定时开关机方法
  16. Google Guava简介
  17. 奇迹 与服务器连接中断,奇迹少女连接服务器失败 连接不上网络怎么办
  18. 对物联网的感悟_物联网心得体会总结
  19. 号称全网最全CAD组合键功能详解
  20. 树状数组详解(附图解,模板及经典例题分析)

热门文章

  1. python如何将数据生成excel_python的将数据生成excel功能
  2. python 自动化发送邮件_干货 | 解放双手,用Python实现自动发送邮件
  3. mininet编程实现交换机规则的插入、删除与修改。_三层以太网交换机基本原理及转发流程...
  4. SpringBoot使用thymefeal出现No mapping for GET /xxx的解决办法
  5. [渝粤教育] 西南科技大学 货币银行学 在线考试复习资料(2)
  6. vc下动态改变鼠标光标
  7. ubuntu16.04中创建新用户
  8. matlab注释的方法
  9. Java json字符串转Object
  10. 浅谈欧几里得算法求最大公约数(GCD)的原理及简单应用