parsing HTML results

Discussion in 'Perl' started by John Raines, Dec 10, 2006.

  1. John Raines

    John Raines Guest

    Hello-

    I am trying to parse HTML results which look like this:

    <html>
    <body>
    <span class=aaa>this is a test</span><span class=bbb>testing
    again</span><span class=aaa>test number 3</span>
    </body>
    </html>

    All the <span> are on one line.

    In this particular case, I want to match all the <span class=aaa> so that my
    results would look like:

    this is a test
    test number 3

    I was fairly successful with a regex like /<span class=aaa>(.*)</span>/ but
    I could only get the first result.

    Is there an easy way to match <span class=aaa>*</span> and return the
    contents within the tag? And to either insert the results into an array, or
    have the ability to loop through the results?

    Thanks
     
    John Raines, Dec 10, 2006
    #1
    1. Advertising

  2. John Raines wrote:
    > I am trying to parse HTML results which look like this:

    [...]
    This has been discussed a gazillion of times.

    > Is there an easy way to match <span class=aaa>*</span> and return the
    > contents within the tag? And to either insert the results into an
    > array, or have the ability to loop through the results?


    Absolutely. The best way to do it is as described in the FAQ: just use a
    parser to parse HTML.

    jue
     
    Jürgen Exner, Dec 10, 2006
    #2
    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. Monique Y. Mudama
    Replies:
    1
    Views:
    475
    Monique Y. Mudama
    Jun 28, 2005
  2. Naren
    Replies:
    0
    Views:
    599
    Naren
    May 11, 2004
  3. lovecreatesbeauty
    Replies:
    8
    Views:
    1,724
    Old Wolf
    Sep 12, 2005
  4. Lawrence

    web engine - parsing results

    Lawrence, Feb 25, 2008, in forum: C++
    Replies:
    0
    Views:
    322
    Lawrence
    Feb 25, 2008
  5. Ken Fine
    Replies:
    3
    Views:
    561
    Steven Cheng [MSFT]
    Jul 23, 2008
Loading...

Share This Page