| View previous topic :: View next topic |
| Author |
Message |
youlikethaaaat Guest
|
Posted: Sun Nov 02, 2008 7:50 pm Post subject: |
|
|
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  |
|
| Back to top |
|
 |
tank
Joined: 21 Dec 2007 Posts: 2294 Location: Louisville KY USA
|
Posted: Sun Nov 02, 2008 9:33 pm Post subject: |
|
|
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 |
|
 |
youlikethaaaat Guest
|
Posted: Sun Nov 02, 2008 10:37 pm Post subject: |
|
|
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  |
|
| Back to top |
|
 |
tank
Joined: 21 Dec 2007 Posts: 2294 Location: Louisville KY USA
|
Posted: Mon Nov 03, 2008 1:56 am Post subject: |
|
|
| 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  _________________ Basic Webpage Controls with JavaScript / COM - Tutorial by Jethrow
 |
|
| Back to top |
|
 |
silkcom
Joined: 23 Jan 2008 Posts: 154
|
Posted: Mon Nov 03, 2008 3:07 pm Post subject: |
|
|
| 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 |
|
 |
silkcom
Joined: 23 Jan 2008 Posts: 154
|
Posted: Wed Jan 07, 2009 6:49 pm Post subject: |
|
|
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. |
|
| Back to top |
|
 |
tank
Joined: 21 Dec 2007 Posts: 2294 Location: Louisville KY USA
|
Posted: Wed Jan 07, 2009 8:52 pm Post subject: |
|
|
| 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 |
|
 |
silkcom
Joined: 23 Jan 2008 Posts: 154
|
Posted: Wed Jan 07, 2009 9:07 pm Post subject: |
|
|
where are you finding these com calls?
note: it doesn't seem to be trying to go to the new address? |
|
| Back to top |
|
 |
tank
Joined: 21 Dec 2007 Posts: 2294 Location: Louisville KY USA
|
Posted: Wed Jan 07, 2009 9:14 pm Post subject: |
|
|
| 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 |
|
 |
silkcom
Joined: 23 Jan 2008 Posts: 154
|
Posted: Wed Jan 07, 2009 9:21 pm Post subject: |
|
|
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 |
|
 |
tank
Joined: 21 Dec 2007 Posts: 2294 Location: Louisville KY USA
|
Posted: Wed Jan 07, 2009 9:42 pm Post subject: |
|
|
| 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 |
|
 |
silkcom
Joined: 23 Jan 2008 Posts: 154
|
Posted: Wed Jan 07, 2009 9:45 pm Post subject: |
|
|
| 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 |
|
 |
Guest
|
Posted: Wed Jan 07, 2009 10:12 pm Post subject: |
|
|
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  |
|
| Back to top |
|
 |
tank
Joined: 21 Dec 2007 Posts: 2294 Location: Louisville KY USA
|
|
| Back to top |
|
 |
Lazy1 Guest
|
Posted: Sat Jan 10, 2009 10:20 pm Post subject: |
|
|
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  |
|
| Back to top |
|
 |
|