BeautifulSoup_python3
2024-05-19 12:50:47
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相关推荐
- python3 beautifulsoup_Python3中BeautifulSoup的使用方法
原标题:Python3中BeautifulSoup的使用方法
- python beautifulsoup_Python3 安装Beautifulsoup
Python3 安装Beautifulsoup admin • 2019 年 11 月 22 日 [title]Beautifulsoup介绍[/title] HTML 文档本身是结构化的文本,有一定 ...
最新文章
- wp 删除独立存储空间文件(多级非空文件夹删除)
- 网站开启https后很慢_HTTPS会影响网站打开速度吗
- pythonweb毕业设计-[分享]我发现了一个快速完成物联网毕业设计的好方法!
- DrawerLayout
- 看看比尔·盖茨在关注什么
- awk的sub函数和gsub函数的用法
- ASP.NET知识集
- ORACLE连接数据库(备忘)
- Swagger自动接口文档生成框架————springboot整合swagger总结
- python圣诞树编写实例详解
- 【Flink】FlinkException The file LOG does not exist on the TaskExecutor
- php的核心类 控制,phpMVC框架的核心启动类定义
- 揭秘315黑客wifi,如何保障APP数据安全
- ERD-ONLINE 免费在线数据库建模工具
- windows定时开关机方法
- Google Guava简介
- 奇迹 与服务器连接中断,奇迹少女连接服务器失败 连接不上网络怎么办
- 对物联网的感悟_物联网心得体会总结
- 号称全网最全CAD组合键功能详解
- 树状数组详解(附图解,模板及经典例题分析)
热门文章
- python如何将数据生成excel_python的将数据生成excel功能
- python 自动化发送邮件_干货 | 解放双手,用Python实现自动发送邮件
- mininet编程实现交换机规则的插入、删除与修改。_三层以太网交换机基本原理及转发流程...
- SpringBoot使用thymefeal出现No mapping for GET /xxx的解决办法
- [渝粤教育] 西南科技大学 货币银行学 在线考试复习资料(2)
- vc下动态改变鼠标光标
- ubuntu16.04中创建新用户
- matlab注释的方法
- Java json字符串转Object
- 浅谈欧几里得算法求最大公约数(GCD)的原理及简单应用