need help to download one link among many links on a Http site Topic is solved

Get help with using AutoHotkey (v1.1 and older) and its commands and hotkeys
shadad
Posts: 32
Joined: 23 Jun 2018, 05:21

need help to download one link among many links on a Http site

28 Jul 2021, 00:48

Hi there :)

I made a simple Powershell script allow me to Download the latest definition file from Symantec. its basically search about the newest/ recent file that contain the name "core3sdssepv5i64.exe" then get its link and start download it. simple and easy as below :

Code: Select all

# Find latest installer
$url = 'https://definitions.symantec.com/defs/download/symantec_enterprise/index.html/'
$site = Invoke-WebRequest -UseBasicParsing -Uri $url
$table = $site.links | ?{ $_.tagName -eq 'A' -and $_.href.ToLower().Contains('core3sdssepv5i64') -and $_.href.ToLower().EndsWith("exe") } | sort href -desc | select href -first 1
$filename = $table.href.ToString()
# Download installer
$src = $filename
$filenameEXT = $SRC.Substring($SRC.LastIndexOf("/") + 1)
$location= (Get-Item -Path '.\' -Verbose).FullName
#write-output $location
Invoke-WebRequest $SRC -OutFile $location\$filenameEXT
Am trying to achieve the same thing using the Autohotkey but am lost. am still learning but cant get my ideas on how to do it. so far i reach to this part where i can get the site to HTML to Var. can anyone assist or maybe re write or at less show me the best way to achive my goal ? here is what i manage to do :

Code: Select all

; Example: Download text to a variable:
whr := ComObjCreate("WinHttp.WinHttpRequest.5.1")
whr.Open("GET", "https://definitions.symantec.com/defs/download/symantec_enterprise/index.html/", true)
whr.Send()
; Using 'true' above and the call below allows the script to remain responsive.
whr.WaitForResponse()
HtmlText := whr.ResponseText
FileAppend, %HtmlText%, foo.html
Run, foo.html
ExitApp
AHKStudent
Posts: 1472
Joined: 05 May 2018, 12:23

Re: need help to download one link among many links on a Http site

28 Jul 2021, 01:49

a better solution is probably a regex that matches the name and returns the full url.

Code: Select all

file := "core3sdssepv5i64"
html := URLDownloadToVar("https://definitions.symantec.com/defs/download/symantec_enterprise/index.html")
document := ComObjCreate("HTMLfile")
document.write("<meta http-equiv=""X-UA-Compatible"" content=""IE=EDGE"">")
document.designMode := "on"
document.write(HTML)
links := document.getElementsByTagName("a")
loop, % (links.length - 1)
{
	if instr(links[a_index-1].innerText, file) {
		MsgBox, % links[a_index-1].href
		break
	}
}
URLDownloadToVar(url){
	hObject:=ComObjCreate("WinHttp.WinHttpRequest.5.1")
	hObject.Open("GET",url)
	hObject.Send()
	return hObject.ResponseText
}
shadad
Posts: 32
Joined: 23 Jun 2018, 05:21

Re: need help to download one link among many links on a Http site

28 Jul 2021, 02:06

AHKStudent wrote:
28 Jul 2021, 01:49
a better solution is probably a regex that matches the name and returns the full url.

Code: Select all

file := "core3sdssepv5i64"
html := URLDownloadToVar("https://definitions.symantec.com/defs/download/symantec_enterprise/index.html")
document := ComObjCreate("HTMLfile")
document.write("<meta http-equiv=""X-UA-Compatible"" content=""IE=EDGE"">")
document.designMode := "on"
document.write(HTML)
links := document.getElementsByTagName("a")
loop, % (links.length - 1)
{
	if instr(links[a_index-1].innerText, file) {
		MsgBox, % links[a_index-1].href
		break
	}
}
URLDownloadToVar(url){
	hObject:=ComObjCreate("WinHttp.WinHttpRequest.5.1")
	hObject.Open("GET",url)
	hObject.Send()
	return hObject.ResponseText
}
Thank you Soo much! you are right! :oops:
Your recommendation and script on point. now i can proceed with the rest of my code. thanks again :clap:
shadad
Posts: 32
Joined: 23 Jun 2018, 05:21

Re: need help to download one link among many links on a Http site

28 Jul 2021, 04:47

AHKStudent wrote:
28 Jul 2021, 01:49
a better solution is probably a regex that matches the name and returns the full url.

Code: Select all

file := "core3sdssepv5i64"
html := URLDownloadToVar("https://definitions.symantec.com/defs/download/symantec_enterprise/index.html")
document := ComObjCreate("HTMLfile")
document.write("<meta http-equiv=""X-UA-Compatible"" content=""IE=EDGE"">")
document.designMode := "on"
document.write(HTML)
links := document.getElementsByTagName("a")
loop, % (links.length - 1)
{
	if instr(links[a_index-1].innerText, file) {
		MsgBox, % links[a_index-1].href
		break
	}
}
URLDownloadToVar(url){
	hObject:=ComObjCreate("WinHttp.WinHttpRequest.5.1")
	hObject.Open("GET",url)
	hObject.Send()
	return hObject.ResponseText
}
@AHKStudent
Is is possible to have this script getting the last updated version of the file core3sdssepv5i64? its getting currently the outdated version not the latest. the link contain many versions of the file but under old dates. i just need the latest.

sorry to bother you :)
AHKStudent
Posts: 1472
Joined: 05 May 2018, 12:23

Re: need help to download one link among many links on a Http site  Topic is solved

28 Jul 2021, 05:20

shadad wrote:
28 Jul 2021, 04:47
AHKStudent wrote:
28 Jul 2021, 01:49
a better solution is probably a regex that matches the name and returns the full url.

Code: Select all

file := "core3sdssepv5i64"
html := URLDownloadToVar("https://definitions.symantec.com/defs/download/symantec_enterprise/index.html")
document := ComObjCreate("HTMLfile")
document.write("<meta http-equiv=""X-UA-Compatible"" content=""IE=EDGE"">")
document.designMode := "on"
document.write(HTML)
links := document.getElementsByTagName("a")
loop, % (links.length - 1)
{
	if instr(links[a_index-1].innerText, file) {
		MsgBox, % links[a_index-1].href
		break
	}
}
URLDownloadToVar(url){
	hObject:=ComObjCreate("WinHttp.WinHttpRequest.5.1")
	hObject.Open("GET",url)
	hObject.Send()
	return hObject.ResponseText
}
@AHKStudent
Is is possible to have this script getting the last updated version of the file core3sdssepv5i64? its getting currently the outdated version not the latest. the link contain many versions of the file but under old dates. i just need the latest.

sorry to bother you :)
here is a solution, made it real quick but it will give you the idea.

Code: Select all

file := "core3sdssepv5i64"
html := URLDownloadToVar("https://definitions.symantec.com/defs/download/symantec_enterprise/index.html")
document := ComObjCreate("HTMLfile")
document.write("<meta http-equiv=""X-UA-Compatible"" content=""IE=EDGE"">")
document.designMode := "on"
document.write(HTML)
links := document.getElementsByTagName("tr")
loop, % (links.length - 1)
{
	try {
		if instr(links[a_index-1].getElementsByTagName("td")[0].innerText, file) {
			lastlink := links[a_index-1].getElementsByTagName("td")[0].getElementsByTagName("a")[0].href
			lastfilesize := links[a_index-1].getElementsByTagName("td")[1].innerText
			lastdate := links[a_index-1].getElementsByTagName("td")[2].innerText
		}
	}
}
MsgBox, % lastlink "`n" lastfilesize "`n" lastdate
ExitApp

URLDownloadToVar(url){
	hObject:=ComObjCreate("WinHttp.WinHttpRequest.5.1")
	hObject.Open("GET",url)
	hObject.Send()
	return hObject.ResponseText
}


shadad
Posts: 32
Joined: 23 Jun 2018, 05:21

Re: need help to download one link among many links on a Http site

28 Jul 2021, 05:31

[/quote]

here is a solution, made it real quick but it will give you the idea.

Code: Select all

file := "core3sdssepv5i64"
html := URLDownloadToVar("https://definitions.symantec.com/defs/download/symantec_enterprise/index.html")
document := ComObjCreate("HTMLfile")
document.write("<meta http-equiv=""X-UA-Compatible"" content=""IE=EDGE"">")
document.designMode := "on"
document.write(HTML)
links := document.getElementsByTagName("tr")
loop, % (links.length - 1)
{
	try {
		if instr(links[a_index-1].getElementsByTagName("td")[0].innerText, file) {
			lastlink := links[a_index-1].getElementsByTagName("td")[0].getElementsByTagName("a")[0].href
			lastfilesize := links[a_index-1].getElementsByTagName("td")[1].innerText
			lastdate := links[a_index-1].getElementsByTagName("td")[2].innerText
		}
	}
}
MsgBox, % lastlink "`n" lastfilesize "`n" lastdate
ExitApp

URLDownloadToVar(url){
	hObject:=ComObjCreate("WinHttp.WinHttpRequest.5.1")
	hObject.Open("GET",url)
	hObject.Send()
	return hObject.ResponseText
}


[/quote]

Man! you are Super! :oops:

Thank you soo much.
you responded fast and gave me what i want. i sent you PM. please reply to it.

Return to “Ask for Help (v1)”

Who is online

Users browsing this forum: downstairs, OrangeCat and 187 guests