Parsing

Discussion in 'Python' started by Michael, Jul 10, 2003.

  1. Michael

    Michael Guest

    I have been assigned a project to parse a webpage for data using
    Python. I have finished only basic tutorials. Any suggestions as to
    where I should go from here? Thanks in advance.
    Michael, Jul 10, 2003
    #1
    1. Advertising

  2. (Michael) wrote in
    news::

    > I have been assigned a project to parse a webpage for data using
    > Python. I have finished only basic tutorials. Any suggestions as to
    > where I should go from here? Thanks in advance.
    >


    Parsing? What are you looking for?
    Do you have to download the page as well?

    If it's a fairly simple thing to find, you could use something like;

    >>> import urllib
    >>> source = urllib.urlopen("http://www.google.com").readlines()
    >>> for line in source:
    >>> if line.find("logo.gif") > -1:
    >>> print "Found google logo"


    If the data to find is more complicated, or you need to parse the HTML as
    well, you should look at more string methods, maybe regular expressions
    (import re)...

    Cheers,
    Simon.
    Simon Bayling, Jul 10, 2003
    #2
    1. Advertising

  3. In article <>, Michael wrote:
    > I have been assigned a project to parse a webpage for data using
    > Python. I have finished only basic tutorials. Any suggestions as to
    > where I should go from here? Thanks in advance.



    Try to be a little more specific. Parse for what? Links? Images? Tags?

    Anyway. A good start might be the HTMLParser that comes with the
    batteries since 2.2 if I remember correctly. See

    http://www.python.org/doc/current/lib/htmlparser-example.html

    for a tiny example.

    PterK

    --
    Peter van Kampen
    pterk -- at -- datatailors.com
    Peter van Kampen, Jul 10, 2003
    #3
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. GIMME
    Replies:
    2
    Views:
    873
    GIMME
    Feb 11, 2004
  2. Naren
    Replies:
    0
    Views:
    579
    Naren
    May 11, 2004
  3. Christopher Diggins
    Replies:
    0
    Views:
    610
    Christopher Diggins
    Jul 9, 2007
  4. Christopher Diggins
    Replies:
    0
    Views:
    433
    Christopher Diggins
    Jul 9, 2007
  5. John Levine
    Replies:
    0
    Views:
    729
    John Levine
    Feb 2, 2012
Loading...

Share This Page