Hi, I am hoping I can use AHK to search the html of a page I am on and copy a var.
The var is always at var parid = "032823330117"; in the html. I am not comfortable showing all the html from the page.
Any help would be greatly appreciated.
Thanks,
Troy
Copy a var from html
-
- Posts: 6
- Joined: 16 Jun 2021, 14:12
Re: Copy a var from html
From AHK help how to downlad an internet url to a variable:
Then you can search the text for the string you need, maybe using regex
Code: Select all
whr := ComObjCreate("WinHttp.WinHttpRequest.5.1")
whr.Open("GET", DownloadUrl, true)
whr.Send()
; Using 'true' above and the call below allows the script to remain responsive.
whr.WaitForResponse()
text := whr.ResponseText
MsgBox % text
-
- Posts: 6
- Joined: 16 Jun 2021, 14:12
Re: Copy a var from html
Thanks for the input, This is beyond by abilities.braunbaer wrote: ↑16 Jun 2021, 15:21From AHK help how to downlad an internet url to a variable:
Then you can search the text for the string you need, maybe using regexCode: Select all
whr := ComObjCreate("WinHttp.WinHttpRequest.5.1") whr.Open("GET", DownloadUrl, true) whr.Send() ; Using 'true' above and the call below allows the script to remain responsive. whr.WaitForResponse() text := whr.ResponseText MsgBox % text
-
- Posts: 6
- Joined: 16 Jun 2021, 14:12
Re: Copy a var from html
I should add that the page with the variable is a web page with a frame within the page. My knowledge about html is very limited and my AHK abilities are somewhat limited.
Re: Copy a var from html
I am not comfortable showing all the html from the page.
then what?My knowledge about html is very limited and my AHK abilities are somewhat limited.
Re: Copy a var from html
?
It is beyond your ability to copy and paste this program text into your script?
-
- Posts: 6
- Joined: 16 Jun 2021, 14:12
Re: Copy a var from html
A little help with RegEx Please.
I'm trying to copy the unique 12 digit number which in this case is "042823340064" to the clipboard within my script.
Below is part of the page when I view the frame source. If I use find I only get 1 match for gGlobalParid
This seems to always show up on line 1723 if that makes a difference.
I hope this is enough info for one of you to help me come up with a working RegEx. Since I am not working with a public webpage I don't think I should provide anymore info.
Assistance would be greatly appreciated.
var gTransSubjectPKName = "PARID";
var gUserSuppliedId = "042823340064";
var gTransSearchTable = "IASW_SEARCHTABLE";
var gAltIdUsedForQuery = "False";
var gAutoTabMode = parseInt("1");
var gHideTabs = ("False" == "True");
var gShowPNP = ("True" == "True");
var gPNPWidth = parseInt("156");
var gIsSuper = ("False" == "True");
var gcanAccessAnyTran = ("False" == "True");
var gTransId = parseInt("0");
var gToday = "24-JUN-2021";
var gConfirmOnCommit = "False";
var gParcel = null;
var gTransSubject = "PARID";
var gPriorPin = "042823340064";
var gPriorSubject = "PARID";
var gGlobalParid = "042823340064";
var gSessionIsExpired = false;
var gSubmitFlag = "False";
var gEnableTCM = "N";
I'm trying to copy the unique 12 digit number which in this case is "042823340064" to the clipboard within my script.
Below is part of the page when I view the frame source. If I use find I only get 1 match for gGlobalParid
This seems to always show up on line 1723 if that makes a difference.
I hope this is enough info for one of you to help me come up with a working RegEx. Since I am not working with a public webpage I don't think I should provide anymore info.
Assistance would be greatly appreciated.
var gTransSubjectPKName = "PARID";
var gUserSuppliedId = "042823340064";
var gTransSearchTable = "IASW_SEARCHTABLE";
var gAltIdUsedForQuery = "False";
var gAutoTabMode = parseInt("1");
var gHideTabs = ("False" == "True");
var gShowPNP = ("True" == "True");
var gPNPWidth = parseInt("156");
var gIsSuper = ("False" == "True");
var gcanAccessAnyTran = ("False" == "True");
var gTransId = parseInt("0");
var gToday = "24-JUN-2021";
var gConfirmOnCommit = "False";
var gParcel = null;
var gTransSubject = "PARID";
var gPriorPin = "042823340064";
var gPriorSubject = "PARID";
var gGlobalParid = "042823340064";
var gSessionIsExpired = false;
var gSubmitFlag = "False";
var gEnableTCM = "N";
Re: Copy a var from html
well, assuming u somehow got whatever this is(html source?) stored in a variable somewhere, extracting a 12 digit number with regex goes like so:
Code: Select all
htmlSource =
(
var gTransSubjectPKName = "PARID";
var gUserSuppliedId = "042823340064";
var gTransSearchTable = "IASW_SEARCHTABLE";
var gAltIdUsedForQuery = "False";
var gAutoTabMode = parseInt("1");
var gHideTabs = ("False" == "True");
var gShowPNP = ("True" == "True");
var gPNPWidth = parseInt("156");
var gIsSuper = ("False" == "True");
var gcanAccessAnyTran = ("False" == "True");
var gTransId = parseInt("0");
var gToday = "24-JUN-2021";
var gConfirmOnCommit = "False";
var gParcel = null;
var gTransSubject = "PARID";
var gPriorPin = "042823340064";
var gPriorSubject = "PARID";
var gGlobalParid = "042823340064";
var gSessionIsExpired = false;
var gSubmitFlag = "False";
var gEnableTCM = "N";
)
RegExMatch(htmlSource, "`am)^var [a-zA-Z]+ = ""(\d{12})"";$", M)
MsgBox % M1
-
- Posts: 6
- Joined: 16 Jun 2021, 14:12
Re: Copy a var from html
I tried to run this and I got an AHK error
[Mod edit: [code][/code] tags added.]
I am struggeling to wrap my head around RegExMatch. I thought I could make it work by using the Clipboard as the source but I just get an empty message box. I know all the html source is being copied to the clipboard. See below for what I have tried.braunbaer wrote: ↑16 Jun 2021, 15:21From AHK help how to downlad an internet url to a variable:
Then you can search the text for the string you need, maybe using regexCode: Select all
whr := ComObjCreate("WinHttp.WinHttpRequest.5.1") whr.Open("GET", DownloadUrl, true) whr.Send() ; Using 'true' above and the call below allows the script to remain responsive. whr.WaitForResponse() text := whr.ResponseText MsgBox % text
Code: Select all
#F3::
MouseClick, right, 700, 850, 1,
Send {Up 3}{Enter} ; selects view frame source
Sleep 1000
Clipboard =
Send ^a^c
Sleep 1000
ClipWait
RegExMatch(Clipboard, "`am)^var [a-zA-Z]+ = ""(\d{12})"";$", M)
MsgBox % M1
Return
Re: Copy a var from html
Maybe there is a problem with your url. This works fine:
Code: Select all
NumpadSub::
msgbox % urldownload("https://www.autohotkey.com/")
return
UrlDownload(Url){
whr := ComObjCreate("WinHttp.WinHttpRequest.5.1")
whr.Open("GET", Url, true)
whr.Send()
; Using 'true' above and the call below allows the script to remain responsive.
whr.WaitForResponse()
return whr.ResponseText
}
If I understand you right, you want the number of the line var gGlobalParid = "042823340064";, this number has always 12 digits and the whole text is in the clipboard?I am struggeling to wrap my head around RegExMatch.
Code: Select all
text:=clipboard
regexmatch(text, "var gGlobalParid = "" (\d{12})", result)
msgbox result1
Re: Copy a var from html
u can make it work using the Clipboard as a source. though, whatever u had copied would need to adhere to the format u had specified earlier. the RegEx will match the first line, consisting exactly of:
- var
- space
- a case-insensitive identifier of arbitrary length, consisting of at least one letter(s)
- space
- equals sign
- space
- double quote, ie a regular quote
- exactly 12 digits(and returns them in capturing group 1)
- double quote
- semicolon
-
- Posts: 6
- Joined: 16 Jun 2021, 14:12
Re: Copy a var from html
Swagfag thanks for all of your assistance and patience. I have accomplished what I need for now and I have learned a little more but I have a lot more to learn.swagfag wrote: ↑25 Jun 2021, 19:26u can make it work using the Clipboard as a source. though, whatever u had copied would need to adhere to the format u had specified earlier. the RegEx will match the first line, consisting exactly of:any deviations from that spec will cause the match to fail. probably ur html is actually formatted differently, but since u can't show it. or u could make the regex more lax, but ud have to know how to do that
- var
- space
- a case-insensitive identifier of arbitrary length, consisting of at least one letter(s)
- space
- equals sign
- space
- double quote, ie a regular quote
- exactly 12 digits(and returns them in capturing group 1)
- double quote
- semicolon
Part of the reason it was not working but probably not my only problem was some of the lines on the clipboard exceeded the max character length for AHK. I am certain the way I got it working is not the best but it will do for now.
I'm viewing the frame source on another tab in chrome and using the find function in chrome to find var gGlobalParid then I copied that entire line, closed that tab and used your code to extract the number.
It sure would be nice if the developers of the web page that so many of us work with all day long at my work would make it easier to copy this number. Without doing what I did our only option is to mouse click next to the number and drag across it to highlight because it is a hyperlink. I try to use my mouse as little as possible because it causes pain in my arm and shoulder. I have made a suggestion to them but I don't expect any change.
Thanks again.
Code: Select all
#F3:: ; get pin from html
MouseClick, right, 700, 850, 1,
Send {Up 3}{Enter} ; selects view frame source
Sleep 4000
Send ^f
Send var gGlobalParid
Sleep 500
Send {Esc}
Sleep 300
Send +{End}
Sleep 300
Clipboard =
Send ^c
Sleep 300
Send ^{w}
Sleep 300
ClipWait
clip := Clipboard
RegExMatch(clip, "`am)^var [a-zA-Z]+ = ""(\d{12})"";$", M)
Clipboard := M1
Return