sample code for parsing html file to get contents of td fields

Discussion in 'Python' started by yaffa, Aug 4, 2005.

  1. yaffa

    yaffa Guest

    does anyone have sample code for parsting an html file to get contents
    of a td field to write to a mysql db? even if you have everything but
    the mysql db part ill take it.

    thanks

    yaffa
    yaffa, Aug 4, 2005
    #1
    1. Advertising

  2. yaffa

    William Park Guest

    yaffa <> wrote:
    > does anyone have sample code for parsting an html file to get contents
    > of a td field to write to a mysql db? even if you have everything but
    > the mysql db part ill take it.


    I usually use Expat XML parser to extract the field.
    http://home.eol.ca/~parkw/index.html#expat

    Expat is everywhere. Python has it and even Gawk has it.

    --
    William Park <>, Toronto, Canada
    ThinFlash: Linux thin-client on USB key (flash) drive
    http://home.eol.ca/~parkw/thinflash.html
    BashDiff: Super Bash shell
    http://freshmeat.net/projects/bashdiff/
    William Park, Aug 4, 2005
    #2
    1. Advertising

  3. yaffa

    Bill Mill Guest

    On 4 Aug 2005 11:54:38 -0700, yaffa <> wrote:
    > does anyone have sample code for parsting an html file to get contents
    > of a td field to write to a mysql db? even if you have everything but
    > the mysql db part ill take it.
    >


    Do you want something like this?

    In [1]: x = "something <td><b>something</b> else</td> and\nanother thing <td>in
    a td</td> and again else"

    In [2]: import re

    In [3]: r = re.compile('<td>(.*?)</td>', re.S)

    In [4]: r.findall(x)
    Out[4]: ['<b>something</b> else', 'in a td']

    If not, you'll have to explain more clearly what you want.

    Peace
    Bill Mill
    bill.mill at gmail.com
    Bill Mill, Aug 4, 2005
    #3
  4. yaffa

    Kent Johnson Guest

    Kent Johnson, Aug 4, 2005
    #4
    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. Jake
    Replies:
    0
    Views:
    548
  2. Tim Chase
    Replies:
    0
    Views:
    70
    Tim Chase
    Feb 16, 2014
  3. Terry Reedy
    Replies:
    0
    Views:
    79
    Terry Reedy
    Feb 16, 2014
  4. Tim Chase
    Replies:
    0
    Views:
    84
    Tim Chase
    Feb 16, 2014
  5. Ned Batchelder
    Replies:
    0
    Views:
    75
    Ned Batchelder
    Feb 16, 2014
Loading...

Share This Page