AutoHotkey Community

It is currently May 26th, 2012, 1:50 pm

All times are UTC [ DST ]




Post new topic Reply to topic  [ 45 posts ]  Go to page Previous  1, 2, 3
Author Message
 Post subject:
PostPosted: November 2nd, 2008, 8:50 pm 
heres how i would get html from the first tab in firefox:
Code:
F3::
clipback := clipboard ;backs up the clipboard
clipboard = javascript:alert(document.body.innerHTML) ;sets the clipboard to the command
controlsend, MozillaWindowClass1, ^1, ahk_class MozillaUIWindowClass ;types ctrl + 1 into firefox to goto first tab
controlsend, MozillaWindowClass1, !d, ahk_class MozillaUIWindowClass ;types alt + d to activate address bar
controlsend, MozillaWindowClass1, {bs}^v{enter}, ahk_class MozillaUIWindowClass ;gets rid of existing content, pastes, then submits the command
winwait, ahk_class MozillaDialogClass ;waits for the alert to appear
winActivate, ahk_class MozillaDialogClass ;once its appeared activate it
send, ^a^c{enter} ;send ctrl + a (select all), sends ctrl + c (copys the selected text), then sends enter to close the alert
html := clipboard ; sets the variable containing the html
clipboard := clipback ;restores the clipboard
clipback := ;clears the backup to free up ram
msgbox, html: %html% ;says the html in a message box
return


hope it isnt too commented ;)


Report this post
Top
  
Reply with quote  
 Post subject:
PostPosted: November 2nd, 2008, 10:33 pm 
Offline
User avatar

Joined: December 21st, 2007, 3:14 pm
Posts: 3826
Location: Louisville KY USA
fyi that doesnt get the source content just the body so anything inside outside of body isnt gotten such as style sheets script tags when not within body. however if you substitute
Code:
clipboard = javascript:alert(document.body.innerHTML)
with
Code:
clipboard = javascript:alert(document.documentElement.innerHTML)
then i think that might be a very nice workaround. once you have that you can regex and a parsing loop or artificially create a document object and Use DOM on it like this
Code:
COM_CoInitialize()
doc := COM_CreateObject("{25336920-03F9-11CF-8FD0-00AA00686F13}") ; thanks lexikos for demostrating this technique here
;http://www.autohotkey.com/forum/viewtopic.php?p=166512#166512
COM_Invoke(doc, "write", html)
COM_Invoke(doc, "close")
pAll  :=   COM_Invoke(pAll ,   "all")
pItem  :=   COM_Invoke(pAll,   "item","name id or index") ; substitute appropriate value here
pinnerHtml  :=   COM_Invoke(pItem,   "all")
MsgBox % "the following is the text from a specific element of the document object `n" pinnerHtml
COM_CoUninitialize()

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


Last edited by tank on November 3rd, 2008, 2:55 am, edited 1 time in total.

Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: November 2nd, 2008, 11:37 pm 
thx, just didnt know about documentElement. will be usful for future things i make :)

but all the stuff he needed is unlikely to be in head :p

never knew about that dom.. will also be usful :)


Report this post
Top
  
Reply with quote  
 Post subject:
PostPosted: November 3rd, 2008, 2:56 am 
Offline
User avatar

Joined: December 21st, 2007, 3:14 pm
Posts: 3826
Location: Louisville KY USA
youlikethaaaat wrote:
thx, just didnt know about documentElement. will be usful for future things i make :)

but all the stuff he needed is unlikely to be in head :p

never knew about that dom.. will also be usful :)
you never know with the amount of improperly written html out there 8)

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


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: November 3rd, 2008, 4:07 pm 
Offline

Joined: January 23rd, 2008, 6:38 pm
Posts: 162
tnx tank. Ya, I didn't need this but I'm sure there are others that will read this and be happy it's in there (probably me in the future)


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: January 7th, 2009, 7:49 pm 
Offline

Joined: January 23rd, 2008, 6:38 pm
Posts: 162
ok, :) new question. Is it possible for me to set the address in IE? I'd like to just use the same COM object if possible.

But basically I want to be able to tell it to switch to a different page, and then ideally know when the page is loaded.

And, if possible do all this without the page coming into view.


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: January 7th, 2009, 9:52 pm 
Offline
User avatar

Joined: December 21st, 2007, 3:14 pm
Posts: 3826
Location: Louisville KY USA
Code:
COM_CoInitialize()
pwb := COM_CreateObject("InternetExplorer.Application")
;~ COM_Invoke(pwb , "Visible=", "True") ;"False" ;"True" ;uncomment to show
url=http://google.com
navTrustedForActiveX   =   0x0400
COM_Invoke(pwb,   "Navigate",   url,   navTrustedForActiveX,   "_self")
iWeb_complete(pwb)
url=http://yahoo.com
COM_Invoke(pwb,   "Navigate",   url,   navTrustedForActiveX,   "_self")
iWeb_complete(pwb)
COM_Invoke(pwb,"Quit")


iWeb_complete(pwb)                  ;   returns bool for success or failure
{   
   If  pwb is not Integer         ;   test to see if we have a valid interface pointer
      ExitApp                  ;   ExitApp if we dont
   loop 10                     ;   sets limit if itenerations to 40 seconds 80*500=40000=40 secs
   {   
      If not (rdy:=COM_Invoke(pwb,"readyState") = 4)
         Break            ;   return success
      Sleep,100               ;   sleep half second between cycles
   }
   loop 80                     ;   sets limit if itenerations to 40 seconds 80*500=40000=40 secs
   {   
      If (rdy:=COM_Invoke(pwb,"readyState") = 4)
         Return    1            ;   return success
      Sleep,500               ;   sleep half second between cycles
   }
   Return 0                  ;   lets face it if it got this far it failed
}                        ;   end complete

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


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: January 7th, 2009, 10:07 pm 
Offline

Joined: January 23rd, 2008, 6:38 pm
Posts: 162
where are you finding these com calls?

note: it doesn't seem to be trying to go to the new address?


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: January 7th, 2009, 10:14 pm 
Offline
User avatar

Joined: December 21st, 2007, 3:14 pm
Posts: 3826
Location: Louisville KY USA
silkcom wrote:
where are you finding these com calls?

MSDN
silkcom wrote:
note: it doesn't seem to be trying to go to the new address?
I tested it it does work you can uncomment
Code:
COM_Invoke(pwb , "Visible=", "True")
to make it visible

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


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: January 7th, 2009, 10:21 pm 
Offline

Joined: January 23rd, 2008, 6:38 pm
Posts: 162
remember i'm using IE 6.

I changed the line to:
COM_Invoke(pwin, "Navigate", url) ;note - pwin is what it was called earlier, so i changed it to be the same here too.

and it now navigates, but still doesn't know whether or not it's finished loading.

getting close though.


NOTE:
rdy := COM_Invoke(pwin,"readyState")
yell2("rdy = " rdy)

prints out "rdy = " to my log


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: January 7th, 2009, 10:42 pm 
Offline
User avatar

Joined: December 21st, 2007, 3:14 pm
Posts: 3826
Location: Louisville KY USA
silkcom wrote:
remember i'm using IE 6.

I changed the line to:
COM_Invoke(pwin, "Navigate", url) ;note - pwin is what it was called earlier, so i changed it to be the same here too.

and it now navigates, but still doesn't know whether or not it's finished loading.

getting close though.


NOTE:
rdy := COM_Invoke(pwin,"readyState")
yell2("rdy = " rdy)

prints out "rdy = " to my log

pwb is an iWebBrowser2 object
pwin is a window object
they are not interchangeable
for the navigate you will want to use pwb(or whatever you change its name to like pweb) instead of a pwin object
For the com functions IE6 vs IE7 makes no difference in my examples

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


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: January 7th, 2009, 10:45 pm 
Offline

Joined: January 23rd, 2008, 6:38 pm
Posts: 162
is there anyway to use the same pwin object as before? Or something from this pwin object? I'd like to be doing this to a specific IE window. I check to see what it is, then move to the next, and check that one, etc.


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: January 7th, 2009, 11:12 pm 
pwin aka window is a member object of document whcich is a member object of iWebBrowser2
iWebBrowser2
single tab of IE7 or an instance of an IE6 browser
as well as a gui browser object
Document
the content within the browser this is the beginning acces to the
Document
Object
Model
Which gives you access to element collections and actual page content
pwin aka Window object
this is the toplevel DOM object of page content and is the parent to Document.

Code:
iWebBrowser2 --------------
                           |
Window                     |
   ^                       |
Document       <-----------|

Sorry my Ascii art sux but you get the idea
Document and window are both specific to the content
if the content changes you need to get a new document and or window pointer but the iWebBrowser2 object would be the same

I hope that clears that up a bit :idea:


Report this post
Top
  
Reply with quote  
 Post subject:
PostPosted: January 7th, 2009, 11:15 pm 
Offline
User avatar

Joined: December 21st, 2007, 3:14 pm
Posts: 3826
Location: Louisville KY USA
sorry guest was me some how i keep getting logged out lately

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


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: January 10th, 2009, 11:20 pm 
There is also the option to combine the iMacros Firefox addon with AHK (via command line). This way one does not have to "mess" with all the DOM stuff (too complicated for me ;)


Report this post
Top
  
Reply with quote  
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 45 posts ]  Go to page Previous  1, 2, 3

All times are UTC [ DST ]


Who is online

Users browsing this forum: Bing [Bot], patgenn123, poserpro and 16 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