AutoHotkey Community

It is currently May 27th, 2012, 11:49 am

All times are UTC [ DST ]




Post new topic Reply to topic  [ 2 posts ] 
Author Message
PostPosted: August 1st, 2010, 12:33 pm 
Offline

Joined: May 13th, 2009, 11:30 pm
Posts: 11
I've used AutoHotKey quite a bit, but never COM objects. I'm trying to parse an HTML table, but I'm not sure the best way to do it.

I figured I could use the HTMLFile object to load the HTML file, then grab the table in it and put it into a 2D array. From there, I'll be in more familiar territory.

Here's where I've got to. Not far but at least it compiles! Could someone give me some pointers please?

Code:
#Include com.ahk

COM_Init()

FileRead, html, C:\Junk\FindFolderMatches\smiths_duplicates.html

doc := COM_CreateObject( "HTMLfile" )
COM_Invoke( doc, "write", html )
loop % COM_Invoke(doc, "all.tags(tr).length")
{
   ; do something
}
Return


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: August 1st, 2010, 3:10 pm 
Offline
User avatar

Joined: December 21st, 2007, 3:14 pm
Posts: 3826
Location: Louisville KY USA
I am super unsure what your intention is, but given your example i might not even use COM

Code:
FileRead, html, C:\Junk\FindFolderMatches\smiths_duplicates.html
msgbox % str_to_array(html,chr(2))



str_to_array(str,delim)
{

   StringReplace,str,str,<tr>,% chr(2),all
   StringSplit,rows,str,% chr(2)
   loop % rows0
   {
      ; skip the first one its everything before the first row
      if a_index = 1
         Continue
   ;~    find the end of the row
      StringReplace,therow,A_LoopField,</tr>,% chr(3),all
      StringSplit,rowsend,therow,% chr(3)
      ahkarray .= striphtml(rowsend1) delim
   }
   Return,ahkarray
}

striphtml(txt)
{
;~       thanks lazlo http://www.autohotkey.com/forum/viewtopic.php?p=71935#71935
   x = %txt%
   Loop Parse, x, <>
      If (A_Index & 1)
         y = %y%%A_LoopField%
   return y
}
also i think
Code:
COM_Invoke(doc, "all.tags(tr).length")
should be
Code:
COM_Invoke(doc, "all.tags[tr].length")
But i dont know this for sure so if it seems to work as is go for it
finally with your existing com code you could sdo something like this
Code:
 someuniquedelimiter := chr(2)
 ahkarray .= com_invoke(doc,"all.tags[tr].item[" a_index-1 "].innerText") someuniquedelimiter

_________________
No matter what your oppinion Please join this discussion
Formal request to Polyethene
Image


Report this post
Top
 Profile  
Reply with quote  
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 2 posts ] 

All times are UTC [ DST ]


Who is online

Users browsing this forum: Bing [Bot], BrandonHotkey, MSN [Bot] and 17 guests


You can post new topics in this forum
You can reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Powered by phpBB® Forum Software © phpBB Group