parse HTML by class rather than tag

Discussion in 'Python' started by lorean2007@yahoo.fr, Feb 23, 2007.

  1. Guest

    Hello,

    i'm would be interested in parsing a HTML files by its corresponding
    opening and closing tags but by taking into account the class
    attributes and its values,

    <html>
    <body>
    ....
    <div class="one">
    ....
    <div class="two">
    </div>
    ....
    </div>
    ....
    <div class="one">...</div>
    <a href="..." class="three">
    </body>
    </html>

    in this example, i will need all content inside div with class="two",
    or only class="one",

    so i wondering if i should go with regular expression, but i do not
    think so as i must jumpt after inner closing div, or with a simple
    parser, i've searched and found
    http://www.diveintopython.org/html_processing/basehtmlprocessor.html
    but i would like the parser not to change anything at all (no
    lowercase).

    can you help ?

    best.
     
    , Feb 23, 2007
    #1
    1. Advertising

  2. Guest

    On Feb 23, 8:54 am, wrote:
    > Hello,
    >
    > i'm would be interested in parsing a HTML files by its corresponding
    > opening and closing tags but by taking into account the class
    > attributes and its values,

    [...]
    > so i wondering if i should go with regular expression, but i do not
    > think so as i must jumpt after inner closing div, or with a simple
    > parser, i've searched and foundhttp://www.diveintopython.org/html_processing/basehtmlprocessor.html
    > but i would like the parser not to change anything at all (no
    > lowercase).


    Horribly brittle idea. Use a robust HTML parser (e.g.
    http://www.crummy.com/software/BeautifulSoup/) to build a document
    tree, then visit it top down and look at the value of the 'class'
    attributes.

    Regards,
    Lorenzo Gatti
     
    , Feb 23, 2007
    #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. Sky
    Replies:
    1
    Views:
    530
    Natty Gur
    Jan 29, 2004
  2. shruds
    Replies:
    1
    Views:
    957
    John C. Bollinger
    Jan 27, 2006
  3. mark4asp
    Replies:
    8
    Views:
    6,774
    Andy Dingley
    Mar 17, 2008
  4. QQ
    Replies:
    2
    Views:
    960
    Patricia Shanahan
    May 1, 2008
  5. Replies:
    2
    Views:
    482
    Bruno Desthuilliers
    May 26, 2008
Loading...

Share This Page