博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
BeautifulSoup4 UserWarning
阅读量:4287 次
发布时间:2019-05-27

本文共 941 字,大约阅读时间需要 3 分钟。

错误描述:

/opt/ActivePython-2.7/lib/python2.7/site-packages/bs4/__init__.py:166: 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.

To get rid of this warning, change this:
 BeautifulSoup([your markup])
to this:
 BeautifulSoup([your markup], "lxml")

  markup_type=markup_type))

解决:

初始化时,加上解析器类型,常用解析器如下:

解析器 使用方法 优势 劣势
Python标准库 BeautifulSoup(markup, "html.parser")
  • Python的内置标准库
  • 执行速度适中
  • 文档容错能力强
  • Python 2.7.3 or 3.2.2)前 的版本中文档容错能力差
lxml HTML 解析器 BeautifulSoup(markup, "lxml")
  • 速度快
  • 文档容错能力强
  • 需要安装C语言库
lxml XML 解析器

BeautifulSoup(markup, ["lxml", "xml"])

BeautifulSoup(markup, "xml")

  • 速度快
  • 唯一支持XML的解析器
  • 需要安装C语言库
html5lib BeautifulSoup(markup, "html5lib")
  • 最好的容错性
  • 以浏览器的方式解析文档
  • 生成HTML5格式的文档
  • 速度慢
  • 不依赖外部扩展
你可能感兴趣的文章
iOS之UIImageView和UIImage
查看>>
iOS OC原生的输入输出流结合socket实现即时通讯
查看>>
iOS AsynSocket实现即时通讯
查看>>
iOS VFL语言
查看>>
iOS UIPopoverController以及iOS9以后UIPopPresentationController的使用、封装到分类中
查看>>
宏定义
查看>>
OC中字符串的操作
查看>>
ios之NSFileManager文件操作
查看>>
iOS NSThread多线程枷锁
查看>>
ios/OC之调用系统相机录像、拍照、打开相册
查看>>
iOS中需要重新布局的几中情况调用的方法
查看>>
iOS. NSCache的缓存
查看>>
iOS之属性引用self.xx与_xx的区别
查看>>
iOS 项目的基本配置bundleId/版本命名/....
查看>>
iOS之CoreImage图像处理框架
查看>>
iOS tableview中cell设置的注意事项
查看>>
iOS之文本处框架CoreText(C语言的框架)
查看>>
iOS之文本处理框架TextKit介绍/NSMutableString
查看>>
iOS. Instruments的使用
查看>>
iOS中显示GIF动画
查看>>