小编Tar*_*day的帖子

名称错误“html”未用 beautifulsoup4 定义

我的 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)
Run Code Online (Sandbox Code Playgroud)

我收到这个错误

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
Run Code Online (Sandbox Code Playgroud)

现在我明白 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. …

html python beautifulsoup python-3.x

2
推荐指数
1
解决办法
1万
查看次数

标签 统计

beautifulsoup ×1

html ×1

python ×1

python-3.x ×1