locked
Importing data from html table RRS feed

  • Question

  • Is there an easy way to import data from html table in a html file in Visual foxpro 9.

    Thanks

    Saturday, July 21, 2012 1:42 PM

Answers

  • Try this code. It will navigate to any url/file and extract all tables data to a txt file with a tab delimiter.

    ************************************************
    * Extract text delimited data from html tables
    * Marco Plaza
    ************************************************

    url='http://www.w3schools.com/html/html_tables.asp'

    oform=createobject('formexp')

    with oform.explorer

        .navigate(url)

        do while .readystate # 4 or .busy
            doevents
        enddo

        tc=.document.getelementsbytagname('table')

    endwith

    messagebox('found '+transform(tc.length)+' tables ',0)


    #define tab chr(9)

    set textmerge to 'datafromHtmlTables.txt' noshow
    set textmerge on

    for each table in tc

    \***************TABLE****************
        crows=table.getelementsbytagname('tr')
        for each tablerow in crows
    \
            ccells=tablerow.getelementsbytagname('td')
            for each cell in ccells
                \\<<cell.InnerText>><<TAB>>
            endfor
        endfor
    \
    endfor

    set textmerge off
    set textmerge to

    modify file datafromhtmltables.txt


    ********************************************
    define class formexp as form
        add object explorer as sexplorer
    enddefine
    ********************************************

    ********************************************
    define class sexplorer as olecontrol
        oleclass ='shell.explorer.2'
    enddefine
    ********************************************


    Marco Plaza

    • Proposed as answer by Pavel Celba Sunday, July 22, 2012 8:30 AM
    • Marked as answer by Youen Zen Tuesday, July 31, 2012 5:38 AM
    Sunday, July 22, 2012 12:31 AM

All replies

  • Well that depends how easy is to write programs for you...

    There is no command APPEND FROM ... TYPE HTML in VFP but if you look at the HTML source then you may find it not so difficult to write a short program for this purpose. STREXTRACT() function allows to extract whole rows from HTML table, the rest depends on the table contents.

    Saturday, July 21, 2012 2:52 PM
  • Hi,

    try below link. there is one sample given for html to dbf  but this function is dependent on MS Office.

    http://www.foxite.com/archives/html-to-dbf-0000119337.htm

    hth


    Please "Mark as Answer" if this post answered your question. :)

    Kalpesh Chhatrala | Software Developer | Rajkot | India

    Kalpesh 's Blog

    VFP Form to C#, Vb.Net Conversion Utility

    Saturday, July 21, 2012 8:02 PM
    Answerer
  • Try this code. It will navigate to any url/file and extract all tables data to a txt file with a tab delimiter.

    ************************************************
    * Extract text delimited data from html tables
    * Marco Plaza
    ************************************************

    url='http://www.w3schools.com/html/html_tables.asp'

    oform=createobject('formexp')

    with oform.explorer

        .navigate(url)

        do while .readystate # 4 or .busy
            doevents
        enddo

        tc=.document.getelementsbytagname('table')

    endwith

    messagebox('found '+transform(tc.length)+' tables ',0)


    #define tab chr(9)

    set textmerge to 'datafromHtmlTables.txt' noshow
    set textmerge on

    for each table in tc

    \***************TABLE****************
        crows=table.getelementsbytagname('tr')
        for each tablerow in crows
    \
            ccells=tablerow.getelementsbytagname('td')
            for each cell in ccells
                \\<<cell.InnerText>><<TAB>>
            endfor
        endfor
    \
    endfor

    set textmerge off
    set textmerge to

    modify file datafromhtmltables.txt


    ********************************************
    define class formexp as form
        add object explorer as sexplorer
    enddefine
    ********************************************

    ********************************************
    define class sexplorer as olecontrol
        oleclass ='shell.explorer.2'
    enddefine
    ********************************************


    Marco Plaza

    • Proposed as answer by Pavel Celba Sunday, July 22, 2012 8:30 AM
    • Marked as answer by Youen Zen Tuesday, July 31, 2012 5:38 AM
    Sunday, July 22, 2012 12:31 AM
  • Cooool!
    Sunday, July 22, 2012 8:30 AM
  • ;-)


    Marco Plaza

    Monday, July 23, 2012 2:19 AM