First of all, thanks to everyone here (specifically Blackholyman) as I was able to take the pieces from this and set the script to my needs.
I have two final questions which may be better served in a new thread - mods, let me know and I can move it.
As I'm pulling the source code of FF, it opens this up in a new browser window - I then read from that the information I want. How can I open that specific FireFox window where Visible = False? Currently I'm taking the source of the FF page, selecting all, copying all, opening an instance of IE and setting the document.write(clipboard) to the html of the FF source (a little hacky but functional) - I just need to hide the FF window of the source code. I can't load this in IE as it would be a PITA with logins, security credentials and that we don't support IE anything so unfortunately that's not an option.
Secondly, I need a way to setup a listener or a poller script - when something on a FF page occurs, I would like to trigger my scrape script. I thought about doing a polling script that loops every second (seems resource-heavy) and have it look for a specific element that pops up; if so, run the script; if not, keep looping. Is there any way to setup an actual listener so that when that element pops up it activates? I was thinking that it would be similar to how if a captcha box pops up then it runs itself (it's not a captcha box). Thoughts?
Thanks again! Here's the modified finished project - any superfluous code that can be trimmed down?
Code: Select all
;page scraper to log to file to run powerpoint to pass variables into ppt userform
;2013 uknowwhoibe with help from ahkscript.org <3
#SingleInstance, Force
SetTitleMatchMode 2
AutoTrim, off
^!q::
Clipboard = ; empty clipboard
Sleep, 200
IfWinExist, Target Site
WinActivate, Target Site
MsgBox % 3, Launch PPT Builder From This Record? `r Auto-launching in 10 seconds, 10
IfMsgBox No
{
Return
}
If ErrorLevel
{
MsgBox, Navigate to the record you want to setup a demo for then re-run
}
Send, ^u ; FF source code
Sleep, 200
WinActivate, Source of: http://targetsite.com/record/
Sleep, 200
Send, ^a
Sleep, 200
Send, ^c
Sleep, 200
Send, ^w
Sleep, 200
html := Clipboard
wb := ComObjCreate("InternetExplorer.Application")
wb.Visible := false
wb.Navigate("about:blank")
while wb.busy
Sleep 200
wb.document.write(html)
loop % (elements := wb.document.getElementsByTagName("h1")).length
if (elements[A_index-1].getAttribute("data-test-id") = "page.title")
BusinessName := elements[A_index-1].innertext
loop % (elements := wb.document.getElementsByTagName("h4")).length
if (elements[A_index-1].getAttribute("data-test-id") = "page.subtitle")
Segment := elements[A_index-1].innertext
loop % (elements := wb.document.getElementsByTagName("address")).length
if (elements[A_index-1].getAttribute("data-test-id") = "prospect.address")
Address := elements[A_index-1].innertext
loop % (elements := wb.document.getElementsByTagName("A")).length
if (elements[A_index-1].getAttribute("data-test-id") = "prospect.websiteUrl")
Website := elements[A_index-1].innertext
loop % (elements := wb.document.getElementsByTagName("dt")).length
if (elements[A_index-1].getAttribute("data-test-id") = "contact.fullName")
FullName := elements[A_index-1].innertext
loop % (elements := wb.document.getElementsByTagName("dd")).length
if (elements[A_index-1].getAttribute("data-test-id") = "contact.email")
Email := elements[A_index-1].innertext
loop % (elements := wb.document.getElementsByTagName("dd")).length
if (elements[A_index-1].getAttribute("data-test-id") = "prospect.statusDescription")
ProspectStatus := elements[A_index-1].innertext
loop % (elements := wb.document.getElementsByTagName("dd")).length
if (elements[A_index-1].getAttribute("data-test-id") = "prospect.prospectId")
ProspectID := elements[A_index-1].innertext
FormatTime, Time,, MM/dd/yy h:mm tt
StringTrimLeft, Email, Email, 6 ; remove "Email" and just show the email address
StringTrimLeft, ProspectStatus, ProspectStatus, 9 ; remove "Owned by" and just show record owner
;MsgBox %Time% `n %Bname% `n %BusinessName% `n %Segment% `n %Address% `n %Website% `n %FullName% `n %Email% `n %ProspectStatus% `n %ProspectID%
wb.quit
FileDelete, C:\Tools\pptbuilder.txt
FileAppend, %FullName% `r`n %BusinessName% `r`n %Website% `r`n %Address% `r`n %Segment% `r`n `r`n %Time% `r`n %Email% `r`n %ProspectStatus% `r`n %ProspectID%, C:\Tools\demobuilder.txt
Sleep,25
ppa:= "C:\path\POWERPNT.EXE" ; open PPT
Run, %ppa%
Sleep, 25
IfWinExist Microsoft PowerPoint
WinActivate Microsoft PowerPoint
Sleep 1000
; Find ribbon button color and click - sadly, best work around I found
PixelSearch, Px, Py, 0, 0, 2400, 2400, 0xB2852E, 0, Fast
if ErrorLevel
MsgBox, PowerPoint was not found open - please manually click on PPT Builder
else
click %Px%, %Py%
Return