2016-03-20 9 views
1

Benim piton 3.4.4 kodudur:adı hatası 'html' beautifulsoup4 tanımlanmıyo

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) 

ben HTMLParser py2.x olduğunu anlıyoruz Şimdi bu hatayı

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 

alıyorum ve html.parser py3.x ama bunu nasıl çalıştırabilirim? bs4 siteIf 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. söylüyor, ancak 3.x koşuyorum ve ben bir ImportError

cevap

3

hata doğrudur, sen tanımlı değil html yerde bir NameError alıyorum. Bağlandığınız belgeler, "html.parser" dizgesini geçirmeniz gerektiğini gösterir; HTMLParser'ı hiç içe aktarmanız gerektiği gibi görünmüyor.

+0

kutsal ... Vay adam, FML. Benim hatam. Bunun için birkaç saat harcadım. Teşekkürler. – tarunuday

İlgili konular