Page 1 of 1

AHK Webpage Search

Posted: 22 Sep 2017, 13:51
by Mprobiz3
VERY NEW TO SCRIPTING..
Hi I am trying to create a Script to find Words on our 911 Dispatching Site to send a MsgBox when found.
I have tried coping to clipboard and searching it but its not working right. I am wanting to search for the words "Status: Dispatched". If found Create MsgBox Stating the Words that follow "Call Type: " And "Location: "
------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
Status: Dispatched "Find" If Found Then, Find Call Type
Call Number: 0
Call Type: Structure Fire "Find" MsgBox with following words or 20 Letters. Include Location:
Beat:
Location: 123 Forest ST "Also" with following words or 20 Letters
Secondary Location:

Example MsgBox
Dispatched
Structure Fire
123 Forest ST
------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
The Following Never Change, Just what Follows.
Status:
Call Number:
Call Type:
Beat:
Location:
Secondary Location:
------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
If Anyone is able to assist Please Help. Thanks

Re: AHK WEBPAGE SEARCH

Posted: 22 Sep 2017, 16:57
by SirRFI
Show what You tried so far. use [ code=autohotkey ] tag for that.

So, this is your sample input?:

Code: Select all

Status: Dispatched
Call Number: 0
Call Type: Structure Fire
Beat:
Location: 123 Forest ST
Secondary Location:

Re: AHK WEBPAGE SEARCH

Posted: 22 Sep 2017, 18:36
by Mprobiz3
no this is one of the Scripts i have tried

{
Sleep, 5000
Send,^a
Send,^c
ClipWait,2
clip = %clipboard%
Haystack = Status: Dispatched
Needle = Status: Dispatched
IfInString, Haystack, %Needle%
MsgBox, The string was found.
return
else,
Sleep, 1

Re: AHK WEBPAGE SEARCH

Posted: 22 Sep 2017, 22:05
by Xtra

Code: Select all

1::
    Clipboard := ""
    Send,^a
    Send,^c
    ClipWait,2
    MsgBox % CheckStatus(Clipboard)
return

CheckStatus(textString)
{
    items := StrSplit(textString,"`n","`r")
    if InStr(items.1, "Status: Dispatched")
        return strReplace(items.1,"Status: ") . "`n" 
             . strReplace(items.3,"Call Type: ") . "`n" 
             . strReplace(items.5,"Location: ")
    return false
}

/*
Status: Dispatched
Call Number: 0
Call Type: Structure Fire
Beat:
Location: 123 Forest ST
Secondary Location:
*/
HTH

Re: AHK WEBPAGE SEARCH

Posted: 24 Sep 2017, 08:14
by Mprobiz3
To: Xtra
This Script brings back a MsgBox with just a "0". Do i need to add this to what i already have or edit it slightly?
I have tried changing Dispatched to Enroute due to having plenty of Enroute pages to test with. Still just gives "0".
could you maybe explain the setup for CheckStatus?

Re: AHK WEBPAGE SEARCH

Posted: 24 Sep 2017, 08:51
by Mprobiz3
I have Corrected Script. The problem was I deleted parts of what copies to Clipboard from website, do to Private information. The following is how it copies to clipboard. Works great Except for It brings up MsgBox and Include the following, At Hospital Time:, Arrived At Patient Time:. Due to following after Status and Call Type. Is there away to ignore At Hospital Time: And Arrived At Patient Time:. Maybe Ignore After Two Consecutive Spaces? There Are two Spaces Between Available And At Hospital Time:. and same for Call Type:. Thanks

Line,1
Line,2 Welcome FD
Line,3 Current Calls Cleared Call Search Map
Line,4 CAD Web View
Line,5 Unit: FD
Line,6 ORI: 0000000 Staged Time:
Line,7 Officer: Transport Time:
Line,8 Status: Available At Hospital Time:
Line,9 Call Number: 0 Depart Hospital Time:
Line,10 Call Type: Arrived At Patient Time:
Line,11 Beat: En Route Time:
Line,12 Location:
Line,13 Secondary Location:
Line,14 Unit Log: 15 rows
Line,15 Date: to

Re: AHK WEBPAGE SEARCH

Posted: 24 Sep 2017, 14:08
by Mprobiz3
The following Code works, But it Displays a MsgBox when Nothing is found. Change Available to Dispatched and it will display a blank Box. I would like it to have no MsgBox until Dispatched is found.
Thanks anyone's help is greatly appreciated.
___________________________________________________________________________________________________________
"Code"
Loop
{
Sleep, 2000
Send, {F5}
Sleep, 3000
Clipboard := ""
Send,^a
Send,^c
ClipWait,2
MsgBox % CheckStatus(Clipboard)

CheckStatus(textString)
{

items := StrSplit(textString,"`n","`r")
if InStr(items.8, "Status: Available")
return strReplace(items.25,"Status: ") . "`n"

}

}
Return

_______________________________________________________________________________________________________________
"Clipboard"
Items.1
Items.2 Welcome fd
Items.3 Current Calls Cleared Call Search Map
Items.4 CAD Web View
Items.5 Unit: FD
Items.6 ORI: 0000000 Staged Time:
Items.7 Officer: Transport Time:
Items.8 Status: Available At Hospital Time:
Items.9 Call Number: 0 Depart Hospital Time:
Items.10 Call Type: Arrived At Patient Time:
Items.11 Beat: En Route Time:
Items.12 Location:
Items.13 Secondary Location:
Items.14 Unit Log: 15 rows
Items.15 Date: to
Items.16
Items.17
Items.18
Items.19
Items.20
Items.21
Items.22
Items.23 Available 2017-00000939 09/24/2017 01:08:03 Unit Cleared From Call Unit Cleared
Items.24 Available 2017-00000939 09/24/2017 01:08:03 CLR Unit Status Change
Items.25 Dispatched 2017-00000939 09/24/2017 01:05:10 DSP Call Number: 590, Location: 210 ABCDEFG TRL, City, Call Type:

Re: AHK WEBPAGE SEARCH

Posted: 24 Sep 2017, 14:33
by egocarib
I would do this with Regex, though it is probably harder to understand if you are not familiar with Regex.

Code: Select all

Clipboard := ""
Send,^a
Send,^c
ClipWait,2
startPosition := 1
Loop
{
	foundPos := RegExMatch(Clipboard, "O)Status: Dispatched[\S\s]*?(Call Type:.*)[\S\s]*?(Location:.*)", match, startPosition)
	if !foundPos
		Break ;no more matches
	MsgBox(match[1] . "`n" . match[2])
	startPosition := foundPos + match.Len[0]
}

Re: AHK WEBPAGE SEARCH

Posted: 10 Oct 2017, 17:08
by Mprobiz3
How do i Start with Regex i cant found it anywhere for scripting

Re: AHK WEBPAGE SEARCH

Posted: 10 Oct 2017, 17:31
by boiler
Click on the command "RegExMatch" in the code egocarib posted to see the documentation for that command.

AHK Webpage Search and Copy

Posted: 08 Oct 2019, 18:33
by Mprobiz3
Good Afternoon,
I am trying to copy information out of excel file, and past in another window.
I have tried using a way to copy webpage then search for information, but i am unable to find a solve.
if anyone can help i would be very thankful

Re: AHK Webpage Search

Posted: 09 Oct 2019, 01:24
by hd0202
to avoid empty message boxes:

Code: Select all

...
ClipWait,2
If CheckStatus(Clipboard)
	MsgBox % CheckStatus(Clipboard)
Hubert