Created
May 3, 2014 17:11
-
-
Save sidola/df2a5ac8dd4d15517aca to your computer and use it in GitHub Desktop.
AHK - Download HTML data to a file
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
DownloadToFile(url, filename) | |
{ | |
static a := "AutoHotkey/" A_AhkVersion | |
if (!(o := FileOpen(filename, "w")) || !DllCall("LoadLibrary", "str", "wininet") || !(h := DllCall("wininet\InternetOpen", "str", a, "uint", 1, "ptr", 0, "ptr", 0, "uint", 0, "ptr"))) | |
return 0 | |
c := s := 0 | |
if (f := DllCall("wininet\InternetOpenUrl", "ptr", h, "str", url, "ptr", 0, "uint", 0, "uint", 0x80003000, "ptr", 0, "ptr")) | |
{ | |
while (DllCall("wininet\InternetQueryDataAvailable", "ptr", f, "uint*", s, "uint", 0, "ptr", 0) && s > 0) | |
{ | |
VarSetCapacity(b, s, 0) | |
DllCall("wininet\InternetReadFile", "ptr", f, "ptr", &b, "uint", s, "uint*", r) | |
c += r | |
o.rawWrite(b, r) | |
} | |
DllCall("wininet\InternetCloseHandle", "ptr", f) | |
} | |
DllCall("wininet\InternetCloseHandle", "ptr", h) | |
o.close() | |
return c | |
} | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment