Jump to content

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

UrlDownloadToVar


  • Please log in to reply
100 replies to this topic
  • Guests
  • Last active:
  • Joined: --
How can I get it to return Unicode url? I get funny characters

Eddy
  • Guests
  • Last active:
  • Joined: --
This thread is old and forgotte, but here is the new Autohotkey_L way (as far as I can tell, I am new to this COM thing)

UrlDownloadToVar(URL, ByRef aResponse) {
	WebRequest := ComObjCreate("WinHttp.WinHttpRequest.5.1")
	WebRequest.Open("GET", URL)
	WebRequest.Send()
	aResponse := WebRequest.ResponseText
	WebRequest := ""
}

Use at your own risk :p

  • Guests
  • Last active:
  • Joined: --
Hey Eddy,
That works fine, I just needed to modify it alittle so it returns something then append it as html..

UrlDownloadToVar(URL) {
	WebRequest := ComObjCreate("WinHttp.WinHttpRequest.5.1")
	WebRequest.Open("GET", URL)
	WebRequest.Send()
	Return WebRequest.ResponseText
	}

But whats strange is that if I MsgBox results then its all funny characters, but if I append it without any encoding it saves the file as Windows-1256 and I can see the Unicode characters.
I don't know much about how that encoding thing works, so I tested the original UrlDownloadToVar function the same way and it works, it just needs to append data to a file first, I'm sure there is something I'm missing on how this works.
Hopefully someone will explain :D
But I like your function anyway, small and does the job, thanks :)

Gatta
  • Guests
  • Last active:
  • Joined: --
Could You show example working script with some page content in MsgBox? I don't know how to use it. It require COM.ahk?

URL := "http://www.autohotkey.com/"

UrlDownloadToVar(URL) {
   WebRequest := ComObjCreate("WinHttp.WinHttpRequest.5.1")
   WebRequest.Open("GET", URL)
   WebRequest.Send()
   Return WebRequest.ResponseText
   }

MsgBox, % ResponseText

I've tried as above and of course it doesn't work.

  • Guests
  • Last active:
  • Joined: --
Install AutoHotkey_L and try it will work. You don't need COM.ahk

Gatta
  • Guests
  • Last active:
  • Joined: --
I've installed already AHK_L unicode x86.

Above code gives empty MsgBox.

Seans version with COM.ahk runs properly but this not. Could You publish working example?

0x150--ISO
  • Members
  • 657 posts
  • Last active: Apr 07 2012 09:06 PM
  • Joined: 01 Jan 2011
@Gatta the parameter being named the same as the variable is where the confusion lays.
MsgBox, % UrlDownloadToVar( URL ) [color=#008000]; amend[/color]

I'm so glad theres an API example here too albeit old ;)

DataLife
  • Members
  • 1022 posts
  • Last active: Nov 27 2015 01:09 AM
  • Joined: 27 Apr 2008

This thread is old and forgotte, but here is the new Autohotkey_L way (as far as I can tell, I am new to this COM thing)

UrlDownloadToVar(URL, ByRef aResponse) {
	WebRequest := ComObjCreate("WinHttp.WinHttpRequest.5.1")
	WebRequest.Open("GET", URL)
	WebRequest.Send()
	aResponse := WebRequest.ResponseText
	WebRequest := ""
}

Use at your own risk :p



If WebRequest can not find the URL then there is a ugly error message. Is there a way to suppress the error message
----------------------------------------------------------------------------------
Error: 0x80072EE7 -
Source: WinHttp.WinHttpRequest
Description: The server name or address could not be resolved
----------------------------------------------------------------------------------

I can always check the variable to see if the contents is what I am expecting so I don't need this ugly error message popping up.

thanks
DataLife
Check out my scripts.  (MyIpChanger) (XPSnap) (SavePictureAs) All my scripts are tested on Windows 7, AutoHotkey 32 bit Ansi unless otherwise stated.

  • Guests
  • Last active:
  • Joined: --
@DataLife,
How can you do that? The error occurs before you get a chance to check its content.

sinkfaze
  • Moderators
  • 6367 posts
  • Last active: Nov 30 2018 08:50 PM
  • Joined: 18 Mar 2008
Not sure why a ByRef variable is needed so I omitted it in my version:

UrlDownloadToVar(URL) {

	WebRequest :=	ComObjCreate("WinHttp.WinHttpRequest.5.1")
	[color=#FF0000]try	WebRequest.Open("GET",URL)
	catch
		return	0[/color]
	WebRequest.Send()
	return	WebRequest.ResponseText
}

Or if you want the error message returned to you:

UrlDownloadToVar(URL) {

	WebRequest :=	ComObjCreate("WinHttp.WinHttpRequest.5.1")
	try	WebRequest.Open("GET",URL)
	catch	[color=#FF0000]error[/color]
		return	[color=#FF0000]error.Message[/color]
	WebRequest.Send()
	return	WebRequest.ResponseText
}


gwarble
  • Members
  • 624 posts
  • Last active: Aug 12 2016 07:49 PM
  • Joined: 23 May 2009
I'm suppressing the error msg with
ComObjError(false)


DataLife
  • Members
  • 1022 posts
  • Last active: Nov 27 2015 01:09 AM
  • Joined: 27 Apr 2008

I'm suppressing the error msg with

ComObjError(false)

thanks, works perfect.

@DataLife,
How can you do that? The error occurs before you get a chance to check its content.

My variable is blank when using ComObjError(false) and the URL can not be found. ComObjError(false) is exactly what I was looking for.

thanks
DataLife
Check out my scripts.  (MyIpChanger) (XPSnap) (SavePictureAs) All my scripts are tested on Windows 7, AutoHotkey 32 bit Ansi unless otherwise stated.

gwarble
  • Members
  • 624 posts
  • Last active: Aug 12 2016 07:49 PM
  • Joined: 23 May 2009
No prob, thanks to lexikos actually

Works well for me, now i'd like a way to download a limited number of bytes or lines only... if anyone has any tricks...

gwarble

UrlDownloadToVar(URL) {
 ComObjError(false)
 WebRequest := ComObjCreate("WinHttp.WinHttpRequest.5.1")
 WebRequest.Open("GET", URL)
 WebRequest.Send()
 Return WebRequest.ResponseText
}


  • Guests
  • Last active:
  • Joined: --
Thanks for the error free ones guys, appreciated

Richard
  • Members
  • 19 posts
  • Last active: Mar 01 2013 11:20 PM
  • Joined: 21 Jul 2012
I have been trying to find a way to click on links on <!-- m -->http://www.ereaderiq.com/free<!-- m --> with the class blTitle under the book_listings_inner id (i.e. to open up the Amazon page to allow me to purchase the book). Unfortunately, this has turned into a week long learning process without success. Interestingly, the script referred to in this thread appears to be a way for me to pull html from the webpage, which I then could use to find and click on the links. However, when I run the script it does not provide me with all of the html... it stops in the menutable id.

How can I change the script to force it to download all of the html on ereaderiq.com/free?

Here is the script I am using:

;http://www.autohotkey.com/community/viewtopic.php?f=2&t=10466&start=75

URL := "http://www.ereaderiq.com/free/"
;URL := "http://www.autohotkey.com"

UrlDownloadToVar(URL) {
; ComObjError(false)
 WebRequest := ComObjCreate("WinHttp.WinHttpRequest.5.1")
 WebRequest.Open("GET", URL)
 WebRequest.Send()
 Return WebRequest.ResponseText
}

MsgBox, % UrlDownloadToVar( URL ) ; ResponseText