simple Question about using BeautifulSoup

Diez B. Roggisch deets at
Wed Aug 20 16:43:50 CEST 2008

Alexnb wrote:

> 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('')
> 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 mailing list