Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
Import HTML table data into Foxpro table
Message
From
09/10/2006 10:39:30
Suhas Hegde
Dental Surgeon
Sirsi, India
 
 
To
09/10/2006 10:30:07
Cetin Basoz
Engineerica Inc.
Izmir, Turkey
General information
Forum:
Visual FoxPro
Category:
Coding, syntax & commands
Environment versions
Visual FoxPro:
VFP 6 SP5
Miscellaneous
Thread ID:
01160464
Message ID:
01160547
Views:
10
>>>>>Suhas,
>>>>>>how can i import a Html table data into Foxpro table ?
>>>>>>Is there a free Html parser or will I have to scan through the HTML and extract the data ?
>>>>>
>>>>>IE works as a HTML free parser for you.
>>>>>Create an Instance of IE, load the file, walk the Document Object Model (DOM) for the table and extract the data.
>>>>>Works fine for not-too-large files...
>>>>>
>>>>>HTH
>>>>>
>>>>>thomas
>>>>
>>>>
>>>>I did something like this but couldnt get it right
>>>>
>>>>m.o1 = createobject("internetexplorer.application")
>>>>m.o1.navigate2(filename)
>>>>do while m.o1.readystate # 4
>>>>enddo
>>>>?m.o1.document.body.childnodes[1].innertext
>>>>
>>>>That gives all the data in the html but not of the table alone
>>>>also extracting data from the return is not easy because it has no delimiters...
>>>>
>>>>any better way?
>>>
>>>Suhas,
>>>It's not an easy task to read HTML tables into a foxpro table IMHO (using any language, anything). Anyway here is some code to replace your last line:
>>>
>>>LOCAL ix
>>>loTables = o1.document.body.getElementsByTagName('TABLE')
>>>FOR ix = 0 TO loTables.length-1
>>> listCells( loTables.item(m.ix) )
>>>endfor
>>>
>>>FUNCTION listCells( toTable )
>>>LOCAL ix
>>>FOR ix=0 TO toTable.Cells.Length-1
>>>? toTable.Cells[m.ix].rowSpan, ;
>>>	toTable.Cells[m.ix].colSpan, ;
>>>	toTable.Cells[m.ix].nodeName, ;
>>>	toTable.Cells[m.ix].cellIndex,;
>>>	toTable.Cells[m.ix].innerText
>>>endfor
>>>
Cetin
>>
>>The page in question is
>>
>>http://nseindia.com/marketinfo/companyinfo/eod/bmSearch_byDate.jsp?companyname=&Fromday=01&Frommon=10&Fromyr=2006&Today=01&Tomon=03&Toyr=2007&Indicesdata=Get+Results&check=new
>>
>>Can i get the table data into a cursor ?
>>
>>SYMBOL,Company name,Meeting date,Purpose
>>
>>Thanx
>>Suhashegde
>>
>>PS: Just wondering Why didnt u reply soon
>
>Oh you were talking about a specific table:) Ok then this is a quick thrown code to get it:
>
>lcURL = "http://nseindia.com/marketinfo/companyinfo/eod/"+;
>  "bmSearch_byDate.jsp?companyname=&Fromday=01&Frommon=10&"+;
>  "Fromyr=2006&Today=01&Tomon=03&Toyr=2007&Indicesdata=Get+Results&check=new"
>lcLocalFile = Forcepath("myHTMFile.htm", Sys(2023))
>If getFileFromURL(m.lcURL,m.lcLocalFile) = 0
>  o1 = Createobject("internetexplorer.application")
>  o1.navigate2("file://"+m.lcLocalFile)
>  Do While o1.readystate # 4
>  Enddo
>
>  loTables = o1.Document.body.getElementsByTagName('TABLE')
>  HTMLTabletoCursor( loTables.Item(lotables.Length-1) )
>
>  Erase (m.lcLocalFile)
>Endif
>
>
>Function HTMLTabletoCursor( toTable )
>  Local ix,jx,lcTemp, lnHandle
>  lcTemp = Forcepath('nsehtm.tmp',Sys(2023))
>  lnHandle = Fcreate(m.lcTemp)
>  For ix=0 To toTable.Rows.Length-1
>    For jx = 0 To toTable.Rows[m.ix].Cells.Length-1
>      Fwrite(m.lnHandle,toTable.Rows[m.ix].cells[m.jx].innerText)
>      If ( m.jx != toTable.Rows[m.ix].Cells.Length-1)
>        Fwrite(m.lnHandle, ',')
>      Endif
>    Endfor
>    Fwrite(m.lnHandle, Chr(13)+Chr(10))
>  Endfor
>  Fclose(m.lnHandle)
>  Create Cursor myData (f1 c(100),f2 c(100),f3 c(100),f4 c(100))
>  Append From ( m.lcTemp ) Type Delimited
>  Erase ( m.lcTemp )
>  Browse
>
>Procedure getFileFromURL
>  Lparameters tcRemoteFile,tcLocalFile
>  Declare Integer URLDownloadToFile In urlmon.Dll;
>    INTEGER pCaller, String szURL, String szFileName,;
>    INTEGER dwReserved, Integer lpfnCB
>  Return URLDownloadToFile(0, m.tcRemoteFile, m.tcLocalFile, 0, 0)
>
>PS: Couldn't reply sooner because of multiple factors, one was terrible internet connection.
>Cetin


Thanx
that worked like a charm

Suhashegde
Previous
Next
Reply
Map
View

Click here to load this message in the networking platform