469,569 Members | 1,511 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 469,569 developers. It's quick & easy.

Re: simple Question about using BeautifulSoup

On Wed, 20 Aug 2008 07:33:32 -0700 (PDT), Alexnb <al********@gmail.comwrote:
>
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')
urllib.urlopen gives you a file-like object for a resource at an url.

file gives you a file-like object for a file on the local filesystem.

soup = BeautifulSoup(file('/the/name/of/the/file'))

Jean-Paul
Aug 20 '08 #1
1 1278
In article <ma*************************************@python.or g>,
Jean-Paul Calderone <ex*****@divmod.comwrote:
>On Wed, 20 Aug 2008 07:33:32 -0700 (PDT), Alexnb <al********@gmail.comwrote:
>>
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')

urllib.urlopen gives you a file-like object for a resource at an url.

file gives you a file-like object for a file on the local filesystem.

soup = BeautifulSoup(file('/the/name/of/the/file'))
Except that you should use open() instead of file() -- docs prior to
Python 2.5 mistakenly had this reversed.
--
Aahz (aa**@pythoncraft.com) <* http://www.pythoncraft.com/

Adopt A Process -- stop killing all your children!
Aug 24 '08 #2

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
2 posts views Thread by Alexnb | last post: by
reply views Thread by suresh191 | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.