首页 > 解决方案 > Automation: How to get downloaded path of a file that was downloaded from the Web browser

问题描述

I am writing a automation script to download a excel file from a link that was opened using Chrome Browser. Is there a option to get full path of the downloaded Location? This script is going to be run across different machines. So i do not want to specify the default download location in my system and find the file in that path.

I have also tried using Windows CMD where i input the file name in CMD, searches the entire system and pulls the path. But it is taking around 2 to 3 minutes to do this search. Is there any better efficient method like using a JavaScript to get the downloaded location quicker?

Below is the windows command i tried (taking 2 to 3 minutes)..

for /f "delims=" %i in ('dir "<FILENAME>" /b/a-d/od/t:c/s') 
DO echo %i > %tmp%\lastfile.txt

标签: javascriptpowershellgoogle-chromecmdautomation

解决方案


在 JScript 中也是如此。它将 Web 文件写入标准输出。

Sub HttpGet
    On Error Resume Next
    Set File = CreateObject("Microsoft.XMLHTTP")
    File.Open "GET", Arg(1), False
    File.setRequestHeader "User-Agent", "Mozilla/4.0 (compatible; MSIE 8.0; Windows NT 6.0; Trident/4.0; SLCC1; .NET CLR 2.0.50727; Media Center PC 5.0; .NET CLR 1.1.4322; .NET CLR 3.5.30729; .NET CLR 3.0.30618; .NET4.0C; .NET4.0E; BCD2000; BCD2000)"
    File.Send
    txt=File.ResponseText
    'Putting in line endings
    Outp.write txt
    If err.number <> 0 then 
        Outp.writeline "" 
        Outp.writeline "Error getting file" 
        Outp.writeline "==================" 
        Outp.writeline "" 
        Outp.writeline "Error " & err.number & "(0x" & hex(err.number) & ") " & err.description 
        Outp.writeline "Source " & err.source 
        Outp.writeline "" 
        Outp.writeline "HTTP Error " & File.Status & " " & File.StatusText
        Outp.writeline  File.getAllResponseHeaders
        Outp.writeline LCase(Arg(1))
    End If
End Sub

推荐阅读