Jump to content

Sky Slate Blueberry Blackcurrant Watermelon Strawberry Orange Banana Apple Emerald Chocolate
Photo

download a url to a variable.


  • Please log in to reply
10 replies to this topic
maestrith
  • Members
  • 786 posts
  • Last active: Apr 10 2019 01:28 PM
  • Joined: 17 Sep 2005
#SingleInstance,Force
url=https://ahknet.autohotkey.com/~maestrith/commands.xml
hObject:=ComObjCreate("WinHttp.WinHttpRequest.5.1") ;Create the Object
hObject.Open("GET",URL) ;Open communication
hObject.Send() ;Send the "get" request
text:=hObject.ResponseText ;Set the "text" variable to the response
Gui,Add,Edit,w800 h500 -Wrap,%text% ;Create an Edit control
Gui,show ;Show the GUI window
return

 

Hopefully it is easy to use.  Let me know if you need anything explained further.

And for those of you who would like it in a function:

#SingleInstance,Force
url=https://ahknet.autohotkey.com/~maestrith/commands.xml
Gui,Add,Edit,w800 h500 -Wrap,% URLDownloadToVar(url)
Gui,show,
return
URLDownloadToVar(url){
	hObject:=ComObjCreate("WinHttp.WinHttpRequest.5.1")
	hObject.Open("GET",url)
	hObject.Send()
	return hObject.ResponseText
}


guest3456
  • Members
  • 1704 posts
  • Last active: Nov 19 2015 11:58 AM
  • Joined: 10 Mar 2011

for reference:

http://www.autohotke...ldownloadtovar/

and older

http://www.autohotke...ldownloadtovar/



maestrith
  • Members
  • 786 posts
  • Last active: Apr 10 2019 01:28 PM
  • Joined: 17 Sep 2005

yep. the reference that I used is here



ProgrammerPaul
  • Members
  • 75 posts
  • Last active: Oct 05 2017 01:14 PM
  • Joined: 28 May 2009

This is exactly what I was looking for. Thanks for sharing it!



maestrith
  • Members
  • 786 posts
  • Last active: Apr 10 2019 01:28 PM
  • Joined: 17 Sep 2005

This is exactly what I was looking for. Thanks for sharing it!

No problem.  I hope you get some good use out of it :)



bruno
  • Members
  • 635 posts
  • Last active: Nov 04 2015 02:26 PM
  • Joined: 07 Mar 2011

i get an error for https: sites. :S



maestrith
  • Members
  • 786 posts
  • Last active: Apr 10 2019 01:28 PM
  • Joined: 17 Sep 2005

i get an error for https: sites. :S

Which site?  I have not had any trouble with the ones I have tried.



bruno
  • Members
  • 635 posts
  • Last active: Nov 04 2015 02:26 PM
  • Joined: 07 Mar 2011

any twitter site such as https://twitter.com/...

 

AutoHotkey :             v1.1.19.01 Unicode 32-bit (Installed)
SystemModel :             RJ181AA-ABA a1600n
SystemCPU :             AMD Athlon™ 64 X2 Dual Core Processor 3800+
SystemGPU :             NVIDIA GeForce 6150 LE  v6.14.10.8208 @ 256.00 MB RAM
SystemType :             X86-based PC
SystemRAM :             3006 MB
SystemOS :                 WIN_XP 32-bit Service Pack 2 v5.1.2600 (WIN32_NT)
SystemUptime :             4 days 6 hours 11 mins 15 seconds
SystemLocale :             en-US (0x0409)
SystemScreen :             1280x720 (96 DPI)
A_AhkPath :             C:\Program Files\AutoHotkey\AutoHotkey.exe
Ahk_CompilerPath :         C:\Program Files\AutoHotkey\Compiler\Ahk2Exe.exe
Ahk_WindowSpyPath :     C:\Program Files\AutoHotkey\AU3_Spy.exe
MPRESS_IsPresent :         0 (false)



maestrith
  • Members
  • 786 posts
  • Last active: Apr 10 2019 01:28 PM
  • Joined: 17 Sep 2005

I get information back from https://www.twitter.comif you are trying to access information that requires you to login then you need to do some other things.



Masonjar13
  • Members
  • 1517 posts
  • Last active:
  • Joined: 16 Sep 2012
Only just now saw this, decided to whip something up, so why not share it? I also changed your function a bit, due to the requirement of the protocol having to be in the string.

My function returns an object that contains the current external IP, ISP, City, State/Region, and Country of the user. All info is gathered from http://whatismyipaddress.com.
; example script
externalIP(exIpInfo)
msgbox % "IP: " exIpInfo.ip "`nISP: " exIpInfo.isp "`nCity: " exIpInfo.city "`nState/Region: " exIpInfo.region "`nCountry: " exIpInfo.country
return

; my function
externalIP(byref ipInfo){
    ipInfo:={}
    tag:=["<!-- do not script -->","</th><td style=""font-size:14px;"">"]
    ipInfoList:=["city","region","country","isp"]
    ipPage:=URLDownloadToVar("http://whatismyipaddress.com/")
    ipStart:=inStr(ipPage,tag[1])+strlen(tag[1])+1,ipInfo.insert("ip",subStr(ipPage,ipStart,inStr(ipPage,tag[1],,,2)-ipStart-1))
    for i,a in ipInfoList
        ipInfo.insert(a,subStr(ipPage,tp:=inStr(ipPage,a ":" tag[2])+strlen(a ":" tag[2]),inStr(ipPage,"<",,tp)-tp))
}

; edited version of maestrith's function
URLDownloadToVar(url){
    if(!regExMatch(url,"i)https?://"))
        url:="https://" url
    hObject:=ComObjCreate("WinHttp.WinHttpRequest.5.1")
    hObject.Open("GET",url)
    hObject.Send()
    return hObject.ResponseText
}
 
Thank you for the function, maestrith. happy.png

OS: Windows 7 Ultimate / Windows 8.1 Pro | Editor: Notepad++


maestrith
  • Members
  • 786 posts
  • Last active: Apr 10 2019 01:28 PM
  • Joined: 17 Sep 2005

Only just now saw this, decided to whip something up, so why not share it? I also changed your function a bit, due to the requirement of the protocol having to be in the string.

My function returns an object that contains the current external IP, ISP, City, State/Region, and Country of the user. All info is gathered from http://whatismyipaddress.com.

; example script
externalIP(exIpInfo)
msgbox % "IP: " exIpInfo.ip "`nISP: " exIpInfo.isp "`nCity: " exIpInfo.city "`nState/Region: " exIpInfo.region "`nCountry: " exIpInfo.country
return

; my function
externalIP(byref ipInfo){
    ipInfo:={}
    tag:=["<!-- do not script -->","</th><td style=""font-size:14px;"">"]
    ipInfoList:=["city","region","country","isp"]
    ipPage:=URLDownloadToVar("http://whatismyipaddress.com/")
    ipStart:=inStr(ipPage,tag[1])+strlen(tag[1])+1,ipInfo.insert("ip",subStr(ipPage,ipStart,inStr(ipPage,tag[1],,,2)-ipStart-1))
    for i,a in ipInfoList
        ipInfo.insert(a,subStr(ipPage,tp:=inStr(ipPage,a ":" tag[2])+strlen(a ":" tag[2]),inStr(ipPage,"<",,tp)-tp))
}

; edited version of maestrith's function
URLDownloadToVar(url){
    if(!regExMatch(url,"i)https?://"))
        url:="https://" url
    hObject:=ComObjCreate("WinHttp.WinHttpRequest.5.1")
    hObject.Open("GET",url)
    hObject.Send()
    return hObject.ResponseText
}

 
Thank you for the function, maestrith. happy.png

 

 

I am just glad you found a use for it :)