未使用beautifulsoup4定义的名称错误'html'

塔伦·乌代(Tarun Uday)

我的python 3.4.4代码是:

import urllib.request
from bs4 import BeautifulSoup
from html.parser import HTMLParser

urls = 'file:///C:/Users/tarunuday/Documents/scrapdata/mech.html'
htmlfile = urllib.request.urlopen(urls)
soup = BeautifulSoup(htmlfile,html.parser)

我收到这个错误

Traceback (most recent call last):
    File "C:\Python34\saved\scrapping\scrapping2.py", line 7, in <module>
    soup = BeautifulSoup(htmlfile,html.parser)
    NameError: name 'html' is not defined

现在我知道HTMLParser是py2.x,而html.parser是py3.x,但是如何使它工作呢?BS4网站If you get the ImportError “No module named html.parser”, your problem is that you’re running the Python 3 version of the code under Python 2.,但我跑3.x和我得到一个NameError不是一个ImportError

丹尼尔·罗斯曼

该错误是正确的,您尚未html在任何地方定义链接到的文档表明您应该以"html.parser"字符串形式进行传递它看起来根本不需要导入HTMLParser。

本文收集自互联网,转载请注明来源。

如有侵权,请联系 [email protected] 删除。

编辑于
0

我来说两句

0 条评论
登录 后参与评论

相关文章

使用Beautifulsoup4从HTML剥离Doctype?

使用BeautifulSoup4和Python3.x无法通过HTML解析理解403错误

使用beautifulsoup4,Python在html标签内查找链接

使用 Python 抓取 HTML 中的特定元素:BeautifulSoup4

用BeautifulSoup4解析HTML表

如何使用Beautifulsoup4刮除属性中未指定类或ID的HTML元素

是否可以在BeautifulSoup4中遍历HTML树?

从抓取的数据中分割html(Python + BeautifulSoup4)

使用beautifulsoup抓取未定义的html错误“ div”

如何使用beautifulsoup4遍历HTML表格并将某些值存储在数组中

解析与beautifulsoup4中的html标记处于同一级别的文本

如何从 BeautifulSoup4 中的 html 标签中找到特定的数据值?

Python BeautifulSoup4解析:Yahoo Finance上的隐藏html元素

HTML文本跨越多行时,如何在beautifulsoup4中返回格式正确的文本

是否可以在HTML Table中移动并在BeautifulSoup4中获取数据?

在Python中用BeautifulSoup4刮擦html并区分相同的标签

如何使用 Beautifulsoup4

ImportError:无法导入名称“ BeautifulSoup4”

错误:未使用Node.js,NPM和Parcel定义HTML onClick

BeautifulSoup4未安装Pipenv

使用 BeautifulSoup 抓取 HTML

带有类别名称的表的Python scrape网站w / BeautifulSoup4 shwoing属性错误

提取HTML并显示beautifulSoup错误

使用 BeautifulSoup 查找自定义 HTML 标签

使用BeautifulSoup将HTML插入html文件

在很大的HTML文件上使用BeautifulSoup-内存错误?

使用 Seaborn 时 BeautifulSoup 模块错误(html 解析器)

在 Python 中使用 BeautifulSoup 解析 HTML 未知错误

jQuery未以HTML形式定义