Copy a var from html

Get help with using AutoHotkey (v1.1 and older) and its commands and hotkeys
t work smarter
Posts: 6
Joined: 16 Jun 2021, 14:12

Copy a var from html

16 Jun 2021, 14:40

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
braunbaer
Posts: 478
Joined: 22 Feb 2016, 10:49

Re: Copy a var from html

16 Jun 2021, 15:21

From AHK help how to downlad an internet url to a variable:

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
Then you can search the text for the string you need, maybe using regex
t work smarter
Posts: 6
Joined: 16 Jun 2021, 14:12

Re: Copy a var from html

16 Jun 2021, 16:12

braunbaer wrote:
16 Jun 2021, 15:21
From AHK help how to downlad an internet url to a variable:

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
Then you can search the text for the string you need, maybe using regex
Thanks for the input, This is beyond by abilities.
t work smarter
Posts: 6
Joined: 16 Jun 2021, 14:12

Re: Copy a var from html

16 Jun 2021, 16:36

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.
swagfag
Posts: 6222
Joined: 11 Jan 2017, 17:59

Re: Copy a var from html

17 Jun 2021, 12:28

I am not comfortable showing all the html from the page.
My knowledge about html is very limited and my AHK abilities are somewhat limited.
then what?
braunbaer
Posts: 478
Joined: 22 Feb 2016, 10:49

Re: Copy a var from html

17 Jun 2021, 12:48

t work smarter wrote:
16 Jun 2021, 16:12
Thanks for the input, This is beyond by abilities.
?
It is beyond your ability to copy and paste this program text into your script?
t work smarter
Posts: 6
Joined: 16 Jun 2021, 14:12

Re: Copy a var from html

24 Jun 2021, 15:09

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";
swagfag
Posts: 6222
Joined: 11 Jan 2017, 17:59

Re: Copy a var from html

24 Jun 2021, 22:36

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
t work smarter
Posts: 6
Joined: 16 Jun 2021, 14:12

Re: Copy a var from html

25 Jun 2021, 10:21

I tried to run this and I got an AHK error
braunbaer wrote:
16 Jun 2021, 15:21
From AHK help how to downlad an internet url to a variable:

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
Then you can search the text for the string you need, maybe using regex
image.png
image.png (15.95 KiB) Viewed 687 times
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.

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
[Mod edit: [code][/code] tags added.]
image.png
image.png (1.34 KiB) Viewed 687 times
braunbaer
Posts: 478
Joined: 22 Feb 2016, 10:49

Re: Copy a var from html

25 Jun 2021, 18:41

t work smarter wrote:
25 Jun 2021, 10:21
I tried to run this and I got an AHK error
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
    }
I am struggeling to wrap my head around RegExMatch.
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?

Code: Select all

text:=clipboard
regexmatch(text, "var gGlobalParid = "" (\d{12})", result)
msgbox result1       
Note that the number is stored in the variable result1, not in the variable result.
swagfag
Posts: 6222
Joined: 11 Jan 2017, 17:59

Re: Copy a var from html

25 Jun 2021, 19:26

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
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
t work smarter
Posts: 6
Joined: 16 Jun 2021, 14:12

Re: Copy a var from html

25 Jun 2021, 22:49

swagfag wrote:
25 Jun 2021, 19:26
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
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
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.

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

Return to “Ask for Help (v1)”

Who is online

Users browsing this forum: Google [Bot], mikeyww, RussF and 134 guests