AutoHotkey Homepage AutoHotkey Community
Let's help each other out
 
 FAQFAQ   SearchSearch   MemberlistMemberlist   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

Watching Firefox's current page (only for IE)
Goto page Previous  1, 2, 3
 
Post new topic   Reply to topic    AutoHotkey Community Forum Index -> Ask for Help
View previous topic :: View next topic  
Author Message
youlikethaaaat
Guest





PostPosted: Sun Nov 02, 2008 7:50 pm    Post subject: Reply with quote

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 Wink
Back to top
tank



Joined: 21 Dec 2007
Posts: 2294
Location: Louisville KY USA

PostPosted: Sun Nov 02, 2008 9:33 pm    Post subject: Reply with quote

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()

_________________
Basic Webpage Controls with JavaScript / COM - Tutorial by Jethrow


Last edited by tank on Mon Nov 03, 2008 1:55 am; edited 1 time in total
Back to top
View user's profile Send private message
youlikethaaaat
Guest





PostPosted: Sun Nov 02, 2008 10:37 pm    Post subject: Reply with quote

thx, just didnt know about documentElement. will be usful for future things i make Smile

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

never knew about that dom.. will also be usful Smile
Back to top
tank



Joined: 21 Dec 2007
Posts: 2294
Location: Louisville KY USA

PostPosted: Mon Nov 03, 2008 1:56 am    Post subject: Reply with quote

youlikethaaaat wrote:
thx, just didnt know about documentElement. will be usful for future things i make Smile

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

never knew about that dom.. will also be usful Smile
you never know with the amount of improperly written html out there Cool
_________________
Basic Webpage Controls with JavaScript / COM - Tutorial by Jethrow
Back to top
View user's profile Send private message
silkcom



Joined: 23 Jan 2008
Posts: 154

PostPosted: Mon Nov 03, 2008 3:07 pm    Post subject: Reply with quote

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)
Back to top
View user's profile Send private message
silkcom



Joined: 23 Jan 2008
Posts: 154

PostPosted: Wed Jan 07, 2009 6:49 pm    Post subject: Reply with quote

ok, Smile 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.
Back to top
View user's profile Send private message
tank



Joined: 21 Dec 2007
Posts: 2294
Location: Louisville KY USA

PostPosted: Wed Jan 07, 2009 8:52 pm    Post subject: Reply with quote

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

_________________
Basic Webpage Controls with JavaScript / COM - Tutorial by Jethrow
Back to top
View user's profile Send private message
silkcom



Joined: 23 Jan 2008
Posts: 154

PostPosted: Wed Jan 07, 2009 9:07 pm    Post subject: Reply with quote

where are you finding these com calls?

note: it doesn't seem to be trying to go to the new address?
Back to top
View user's profile Send private message
tank



Joined: 21 Dec 2007
Posts: 2294
Location: Louisville KY USA

PostPosted: Wed Jan 07, 2009 9:14 pm    Post subject: Reply with quote

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
_________________
Basic Webpage Controls with JavaScript / COM - Tutorial by Jethrow
Back to top
View user's profile Send private message
silkcom



Joined: 23 Jan 2008
Posts: 154

PostPosted: Wed Jan 07, 2009 9:21 pm    Post subject: Reply with quote

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
Back to top
View user's profile Send private message
tank



Joined: 21 Dec 2007
Posts: 2294
Location: Louisville KY USA

PostPosted: Wed Jan 07, 2009 9:42 pm    Post subject: Reply with quote

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
_________________
Basic Webpage Controls with JavaScript / COM - Tutorial by Jethrow
Back to top
View user's profile Send private message
silkcom



Joined: 23 Jan 2008
Posts: 154

PostPosted: Wed Jan 07, 2009 9:45 pm    Post subject: Reply with quote

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.
Back to top
View user's profile Send private message
Guest






PostPosted: Wed Jan 07, 2009 10:12 pm    Post subject: Reply with quote

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
Back to top
tank



Joined: 21 Dec 2007
Posts: 2294
Location: Louisville KY USA

PostPosted: Wed Jan 07, 2009 10:15 pm    Post subject: Reply with quote

sorry guest was me some how i keep getting logged out lately
_________________
Basic Webpage Controls with JavaScript / COM - Tutorial by Jethrow
Back to top
View user's profile Send private message
Lazy1
Guest





PostPosted: Sat Jan 10, 2009 10:20 pm    Post subject: Reply with quote

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 Wink
Back to top
Display posts from previous:   
Post new topic   Reply to topic    AutoHotkey Community Forum Index -> Ask for Help All times are GMT
Goto page Previous  1, 2, 3
Page 3 of 3

 
Jump to:  
You can post new topics in this forum
You can reply to topics in this forum


Powered by phpBB © 2001, 2005 phpBB Group