javascript - 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
解决方案
在 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
推荐阅读
- python - 为什么我非常非常简单的 for 循环会抛出 TypeError
- java - 如何更改 owl api 中现有的 OWLDataPropertyAssertionAxiom 值?
- java - Java忽略异常并继续
- python - django 中是否可以有一个媒体 url 和一个 satic url
- android - 如何选择 JSON 的特定部分并将其转换为使用 Moshi 进行改造的列表
- r-markdown - 在 RStudio 中停用内联块输出缓存
- sql - Postgresql order by 乱序
- java - 如何从给定数组中取出奇数和偶数,然后将它们存储在另一个数组中?
- java - Springfox Swagger - 使用索引显示 ChronoUnit 枚举值
- c - 无法理解电报 cli 源代码中的 C 构造