simple Question about using BeautifulSoup
Diez B. Roggisch
deets at nospam.web.de
Wed Aug 20 16:43:50 CEST 2008
> Okay, I have used BeautifulSoup a lot lately, but I am wondering, how do
> you open a local html file?
> Usually I do something like this for a url
> soup = BeautifulSoup(urllib.urlopen('http://www.website.com')
> but the file extension doesn't work. So how do I open one?
The docs for urllib.urlopen clearly state that it returns a file-like
object. Which BS seems to grok.
So... how about passing another file-like object, like... *drumroll* - a
soup = BeautifulSoup(open("myfile.html"))
Apart from the documented possibility to pass the html as string, which
soup = BeautifulSoup(open("myfile.html").read())
will work as well.
More information about the Python-list