Jump to content
Sign in to follow this  
tommytx

How to select Table 3 of 7 and save to file.

Recommended Posts

tommytx

Can someone offer some advice here, I have an html file that is reporting 7 tables. I need to save table 3 of the group. Obviously I have no idea what I am doing, please help. This particular table has and id="ctl00_SampleContent_Traffic1_gvSourceStats so I could use the id or table number 2... I am counting as 0,1,2,3,4,5,6,7 and using a ($oIE, 2) since I actually need table number 3. Am I even close.. Once I save the extracted table, then I will view just that complete table as it has the stats.. Should I be using the ID since it is available?

$file = FileOpen("savetable.htm", 2)
$oIE = _IECreate ("C:\_____New_Blog_Idea\_download_au3\stats.htm")
$oTable = _IETableGetCollection ($oIE, 2)
For $oTable In $oTables
    FileWrite($file, $oTable.outerHTML & @CRLF)
Next
FileClose($file)
Edited by tommytx

Share this post


Link to post
Share on other sites
PsaltyDS

Use whichever method you think is more likely to be stable (not change in the future). You could even use both, getting the table by 0-based index and then verify it's the right one with:

$oIE = _IECreate ("C:\_____New_Blog_Idea\_download_au3\stats.htm")
$oTable = _IETableGetCollection ($oIE, 2)
If @error Or ($oTable.id & "" <> "ctl00_SampleContent_Traffic1_gvSourceStat") Then
     MsgBox(16, "Error", "Table ID mismatch!")
     Exit
EndIf

Note that if you specify an index, the return value is just the object (on success anyway), not a collection. So the For/In loop is not required.

:blink:

Edited by PsaltyDS

Valuater's AutoIt 1-2-3, Class... Is now in Session!For those who want somebody to write the script for them: RentACoder"Any technology distinguishable from magic is insufficiently advanced." -- Geek's corollary to Clarke's law

Share this post


Link to post
Share on other sites
DaleHohm

Or just

$oTable = _IEGetObjById($oIE, "ctl00_SampleContent_Traffic1_gvSourceStats")

Dale


Free Internet Tools: DebugBar, AutoIt IE Builder, HTTP UDF, MODIV2, IE Developer Toolbar, IEDocMon, Fiddler, HTML Validator, WGet, curl

MSDN docs: InternetExplorer Object, Document Object, Overviews and Tutorials, DHTML Objects, DHTML Events, WinHttpRequest, XmlHttpRequest, Cross-Frame Scripting, Office object model

Automate input type=file (Related)

Alternative to _IECreateEmbedded? better: _IECreatePseudoEmbedded  Better Better?

IE.au3 issues with Vista - Workarounds

SciTe Debug mode - it's magic: #AutoIt3Wrapper_run_debug_mode=Y Doesn't work needs to be ripped out of the troubleshooting lexicon. It means that what you tried did not produce the results you expected. It begs the questions 1) what did you try?, 2) what did you expect? and 3) what happened instead?

Reproducer: a small (the smallest?) piece of stand-alone code that demonstrates your trouble

Share this post


Link to post
Share on other sites
tommytx

Thanks... that sounds like great advice.. I will use it, but I still do not understand how to save the scraped table so that once the single small table has been extracted and saved I can browse to the file and view just the table..

I tried something like this but its not working... I am sure I have not set it up correctly..

FileWrite($file, $oTable.outerHTML & @CRLF) I also added 3 lines to your solution to show you what else I need to accomplish.. I can go in manually and copy the entire small table and save it and it works great in the browser.. but I need to automate it. Isn't there an easy way?

$file = FileOpen("savetable.htm", 2)
$oIE = _IECreate ("C:\_____New_Blog_Idea\_download_au3\stats.htm")
$oTable = _IETableGetCollection ($oIE, 2)
If @error Or ($oTable.id & "" <> "ctl00_SampleContent_Traffic1_gvSourceStat") Then
     MsgBox(16, "Error", "Table ID mismatch!")
     FileWrite($file, $oTable.outerHTML & @CRLF)
     Exit
EndIf
FileClose($file)
Edited by tommytx

Share this post


Link to post
Share on other sites
DaleHohm

See _IETableWriteToArray and its examples.

Dale


Free Internet Tools: DebugBar, AutoIt IE Builder, HTTP UDF, MODIV2, IE Developer Toolbar, IEDocMon, Fiddler, HTML Validator, WGet, curl

MSDN docs: InternetExplorer Object, Document Object, Overviews and Tutorials, DHTML Objects, DHTML Events, WinHttpRequest, XmlHttpRequest, Cross-Frame Scripting, Office object model

Automate input type=file (Related)

Alternative to _IECreateEmbedded? better: _IECreatePseudoEmbedded  Better Better?

IE.au3 issues with Vista - Workarounds

SciTe Debug mode - it's magic: #AutoIt3Wrapper_run_debug_mode=Y Doesn't work needs to be ripped out of the troubleshooting lexicon. It means that what you tried did not produce the results you expected. It begs the questions 1) what did you try?, 2) what did you expect? and 3) what happened instead?

Reproducer: a small (the smallest?) piece of stand-alone code that demonstrates your trouble

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
Sign in to follow this  

×

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.