【发布时间】:2016-03-20 12:39:42
【问题描述】:
我的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 site 说 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
【问题讨论】:
标签: python html python-3.x beautifulsoup