472,102 Members | 1,087 Online
Bytes | Software Development & Data Engineering Community
Post +

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 472,102 software developers and data experts.

simple Question about using BeautifulSoup


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?
--
View this message in context: http://www.nabble.com/simple-Questio...p19069980.html
Sent from the Python - python-list mailing list archive at Nabble.com.

Aug 20 '08 #1
2 5482
On 2008-08-20, Alexnb <al********@gmail.comwroted:
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?
Have you tried the local file URL, like "file:///home/user/file.html"?

GS
--
Grzegorz Staniak <gstaniak _at_ wp [dot] pl>
Aug 20 '08 #2
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('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
file?

soup = BeautifulSoup(open("myfile.html"))

Apart from the documented possibility to pass the html as string, which
means
soup = BeautifulSoup(open("myfile.html").read())

will work as well.

Diez
Aug 20 '08 #3

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

7 posts views Thread by Dan Stromberg | last post: by
1 post views Thread by Dan Stromberg | last post: by
4 posts views Thread by joe_public34 | last post: by
4 posts views Thread by William Xu | last post: by
3 posts views Thread by John Nagle | last post: by
2 posts views Thread by Alexnb | last post: by
1 post views Thread by Alexnb | last post: by
1 post views Thread by Jean-Paul Calderone | last post: by
reply views Thread by leo001 | last post: by

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.