Re: simple Question about using BeautifulSoup

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Jean-Paul Calderone

    Re: simple Question about using BeautifulSoup

    On Wed, 20 Aug 2008 07:33:32 -0700 (PDT), Alexnb <alexnbryan@gma il.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(u rllib.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(f ile('/the/name/of/the/file'))

    Jean-Paul
  • Aahz

    #2
    Re: simple Question about using BeautifulSoup

    In article <mailman.1901.1 219243610.922.p ython-list@python.org >,
    Jean-Paul Calderone <exarkun@divmod .comwrote:
    >On Wed, 20 Aug 2008 07:33:32 -0700 (PDT), Alexnb <alexnbryan@gma il.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(u rllib.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(f ile('/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 (aahz@pythoncra ft.com) <* http://www.pythoncraft.com/

    Adopt A Process -- stop killing all your children!

    Comment

    Working...