Sam2022 Posted October 11, 2021 Share Posted October 11, 2021 (edited) Kindley i need a Code to retrieve file name with extension from this URL : https://www.internetdownloadmanager.com/getlatestversion.html as i paste it to browser adress bar it will give me the Real Link to the file as : https://mirror2.internetdownloadmanager.com/idman639build2.exe?v=lt&filename=idman639build2.exe So i need the Last part which is File Name + extension from the First blind Link not the second Meaning i need a code to read : idman639build2.exe from the Link : https://www.internetdownloadmanager.com/getlatestversion.html directly Thanks in advance Edited October 11, 2021 by Sam2022 Link to comment Share on other sites More sharing options...
Developers Jos Posted October 11, 2021 Developers Share Posted October 11, 2021 4 hours ago, Sam2022 said: Meaning i need a code to read : Great ... so what exactly is your AutoIt3 question or is your wish we code the whole thing for you? Sam2022 1 SciTE4AutoIt3 Full installer Download page - Beta files Read before posting How to post scriptsource Forum etiquette Forum Rules Live for the present, Dream of the future, Learn from the past. Link to comment Share on other sites More sharing options...
Sam2022 Posted October 11, 2021 Author Share Posted October 11, 2021 1 hour ago, Jos said: Great ... so what exactly is your AutoIt3 question or is your wish we code the whole thing for you? #include <MsgBoxConstants.au3> Example() Func Example() ; Read the file without downloading to a folder. The option of 'get the file from the local cache' has been selected. Local $dData = InetRead("https://www.internetdownloadmanager.com/getlatestversion.html") ; The number of bytes read is returned using the @extended macro. Local $iBytesRead = @extended ; Convert the ANSI compatible binary string back into a string. Local $sData = BinaryToString($dData) $IDMGETlink = StringRegExp($dData , '(?:http|https)s?[^"\r\n]+(?:exe)', 1 ) $IDMdownloadURL = $IDMGETlink [ 0 ] MsgBox($MB_SYSTEMMODAL, "", "The File Name or Link is: " & $IDMdownloadURL) ; Display the results. MsgBox($MB_SYSTEMMODAL, "", "The number of bytes read: " & $iBytesRead & @CRLF & @CRLF & $sData) EndFunc ;==>Example So first Message gives nothing but second okay i need the first message to read the file name or the final link Link to comment Share on other sites More sharing options...
Leendert-Jan Posted October 11, 2021 Share Posted October 11, 2021 (edited) Using the command line tool curl it shows you the link you need: C:\Users\User>curl https://www.internetdownloadmanager.com/getlatestversion.html <!DOCTYPE HTML PUBLIC "-//IETF//DTD HTML 2.0//EN"> <html><head> <title>302 Found</title> </head><body> <h1>Found</h1> <p>The document has moved <a href="https://mirror2.internetdownloadmanager.com/idman639build2.exe?v=lt&filename=idman639build2.exe">here</a>.</p> </body></html> Perhaps you can use StringRegExp() to extract the link from the output of this command? (I know there is a cURL UDF, but it does not appear to work with the 64 bit libcurl-x64.dll file) More info: Get output from a command: https://www.autoitscript.com/forum/topic/193401-how-to-get-output-of-run/ StringRegExp function: https://www.autoitscript.com/autoit3/docs/functions/StringRegExp.htm (I am assuming you already know this because you use StringRegExp in your code) Edited October 11, 2021 by Leendert-Jan Sam2022 1 Link to comment Share on other sites More sharing options...
mikell Posted October 11, 2021 Share Posted October 11, 2021 (edited) 23 minutes ago, Leendert-Jan said: Using the command line tool curl it shows you the link you need Right #include <AutoItConstants.au3> $cmd = "curl -sk " & "https://www.internetdownloadmanager.com/getlatestversion.html" Local $iPID = Run($cmd, "", @SW_HIDE, $STDOUT_CHILD) ProcessWaitClose($iPID) $file = StringRegExpReplace(StdoutRead($iPID), '(?s).*?filename=([^"]+).*', "$1") Msgbox(0,"", $file) Note that curl could be used to eventually dowload the file too Edited October 11, 2021 by mikell Leendert-Jan and Sam2022 2 Link to comment Share on other sites More sharing options...
Sam2022 Posted October 11, 2021 Author Share Posted October 11, 2021 16 minutes ago, mikell said: Right #include <AutoItConstants.au3> $cmd = "curl -sk " & "https://www.internetdownloadmanager.com/getlatestversion.html" Local $iPID = Run($cmd, "", @SW_HIDE, $STDOUT_CHILD) ProcessWaitClose($iPID) $file = StringRegExpReplace(StdoutRead($iPID), '(?s).*?filename=([^"]+).*', "$1") Msgbox(0,"", $file) Note that curl could be used to eventually dowload the file too The meesage gives blank value Meaning it returns nothing Link to comment Share on other sites More sharing options...
Leendert-Jan Posted October 11, 2021 Share Posted October 11, 2021 (edited) 2 minutes ago, Sam2022 said: The meesage gives blank value Open Command Prompt (cmd) and run curl --version Then post the output here. Edited October 11, 2021 by Leendert-Jan Sam2022 1 Link to comment Share on other sites More sharing options...
Sam2022 Posted October 11, 2021 Author Share Posted October 11, 2021 4 minutes ago, Leendert-Jan said: Open Command Prompt (cmd) and run curl --version Then post the output here. Leendert-Jan 1 Link to comment Share on other sites More sharing options...
Leendert-Jan Posted October 11, 2021 Share Posted October 11, 2021 (edited) cURL is probably is not installed. Download cURL here: https://curl.se/windows/ Extract the zip Copy the file bin\curl.exe to your script's folder. Alternatively you can place the file in C:\Windows\System32. Edit: I asked the output of curl --version, not what you entered Edited October 11, 2021 by Leendert-Jan Sam2022 1 Link to comment Share on other sites More sharing options...
Sam2022 Posted October 11, 2021 Author Share Posted October 11, 2021 9 minutes ago, Leendert-Jan said: cURL is probably is not installed. Download cURL here: https://curl.se/windows/ Extract the zip Copy the file bin\curl.exe to your script's folder. Alternatively you can place the file in C:\Windows\System32. Edit: I asked the output of curl --version, not what you entered Thanks man i'll check all files and your code Leendert-Jan 1 Link to comment Share on other sites More sharing options...
mikell Posted October 11, 2021 Share Posted October 11, 2021 For the fun By checking the download in the Scite console, you could even build a progressbar, a percent progress etc #include <AutoItConstants.au3> $url = "https://www.internetdownloadmanager.com/getlatestversion.html" ; get filename $cmd = "curl -sk " & $url Local $iPID = Run($cmd, "", @SW_HIDE, $STDOUT_CHILD) ProcessWaitClose($iPID) $file = StringRegExpReplace(StdoutRead($iPID), '(?s).*?filename=([^"]+).*', "$1") Msgbox(0,"", $file) ; then download $cmd = 'curl -Lk ' & $url SplashTextOn ("", "Downloading ...", 300, 55, -1, 350, 49, "", 12) Local $iPID = Run($cmd, "", @SW_HIDE, $STDOUT_CHILD) ProcessWaitClose($iPID) Local $out = StdoutRead($iPID) SplashOff() $h = Fileopen(@desktopdir & "\" & $file, 18) Filewrite($h, $out) Fileclose($h) Sam2022 1 Link to comment Share on other sites More sharing options...
Sam2022 Posted October 11, 2021 Author Share Posted October 11, 2021 6 hours ago, mikell said: For the fun By checking the download in the Scite console, you could even build a progressbar, a percent progress etc #include <AutoItConstants.au3> $url = "https://www.internetdownloadmanager.com/getlatestversion.html" ; get filename $cmd = "curl -sk " & $url Local $iPID = Run($cmd, "", @SW_HIDE, $STDOUT_CHILD) ProcessWaitClose($iPID) $file = StringRegExpReplace(StdoutRead($iPID), '(?s).*?filename=([^"]+).*', "$1") Msgbox(0,"", $file) ; then download $cmd = 'curl -Lk ' & $url SplashTextOn ("", "Downloading ...", 300, 55, -1, 350, 49, "", 12) Local $iPID = Run($cmd, "", @SW_HIDE, $STDOUT_CHILD) ProcessWaitClose($iPID) Local $out = StdoutRead($iPID) SplashOff() $h = Fileopen(@desktopdir & "\" & $file, 18) Filewrite($h, $out) Fileclose($h) Thanks Man vey good and clear Link to comment Share on other sites More sharing options...
NewCommer Posted October 16, 2021 Share Posted October 16, 2021 You can use @trancexx excellent UDF WinHttp.au3 to receive and send http requests. Main Steps: Disable Redirects -- Send request -- Query Location Header #include "WinHttp.au3" Local $URL = "https://www.internetdownloadmanager.com/getlatestversion.html" Local $aURL = _WinHttpCrackUrl($URL) Local $hOpen = _WinHttpOpen() Local $hConnect = _WinHttpConnect($hOpen, $aURL[2]) Local $hRequest = _WinHttpOpenRequest($hConnect, 'HEAD', $aURL[6], Default, Default, Default) _WinHttpSetOption($hRequest, $WINHTTP_OPTION_DISABLE_FEATURE, $WINHTTP_DISABLE_REDIRECTS) _WinHttpSendRequest($hRequest) _WinHttpReceiveResponse($hRequest) Local $sLocation = _WinHttpQueryHeaders($hRequest, $WINHTTP_QUERY_LOCATION) _WinHttpCloseHandle($hRequest) _WinHttpCloseHandle($hConnect) _WinHttpCloseHandle($hOpen) MsgBox(0, "Location", $sLocation) Sam2022 1 Link to comment Share on other sites More sharing options...
Sam2022 Posted October 17, 2021 Author Share Posted October 17, 2021 On 10/16/2021 at 3:35 PM, NewCommer said: You can use @trancexx excellent UDF WinHttp.au3 to receive and send http requests. Main Steps: Disable Redirects -- Send request -- Query Location Header #include "WinHttp.au3" Local $URL = "https://www.internetdownloadmanager.com/getlatestversion.html" Local $aURL = _WinHttpCrackUrl($URL) Local $hOpen = _WinHttpOpen() Local $hConnect = _WinHttpConnect($hOpen, $aURL[2]) Local $hRequest = _WinHttpOpenRequest($hConnect, 'HEAD', $aURL[6], Default, Default, Default) _WinHttpSetOption($hRequest, $WINHTTP_OPTION_DISABLE_FEATURE, $WINHTTP_DISABLE_REDIRECTS) _WinHttpSendRequest($hRequest) _WinHttpReceiveResponse($hRequest) Local $sLocation = _WinHttpQueryHeaders($hRequest, $WINHTTP_QUERY_LOCATION) _WinHttpCloseHandle($hRequest) _WinHttpCloseHandle($hConnect) _WinHttpCloseHandle($hOpen) MsgBox(0, "Location", $sLocation) Perfect Answer my dear Excellent and working 100% Thanks a lot Accept my respect and best regards Link to comment Share on other sites More sharing options...
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now