使用 VBScript 或 Powershell 从动态链接下载文件 [英] Download file from dynamic link using VBScript or Powershell

查看:20
本文介绍了使用 VBScript 或 Powershell 从动态链接下载文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试创建一个 VBScript 或 Powershell 脚本来从动态链接获取文件(例如 http://www.pepperresources.org/LinkClick.aspx?fileticket=B1doLYYSaeY%3d&tabid=61)

I'm trying to create a VBScript or Powershell script to get the file from dynamic link (e.g. http://www.pepperresources.org/LinkClick.aspx?fileticket=B1doLYYSaeY%3d&tabid=61 )

我应该获取将从那种链接(无论是 PDF、CSV 还是 Excel)下载到指定文件夹的任何文件.知道我是否可以使用 VBScript 或 Powershell Script 来做到这一点吗?

I should get any file that will be downloaded from that kind of link (whether it will be PDF or CSV or Excel) to the specified folder. Any idea if I can do this using VBScript or Powershell Script?

已尝试为此搜索解决方案,但没有成功.

Have been tried to searched the solution for this but no luck.

之前感谢您的帮助.

推荐答案

URL 必须 100% 正确.与浏览器不同,没有修复网址的代码.

The URL has to be 100% correct. Unlike a browser there is no code to fix urls.

我的程序的目的是获取错误详细信息.

The purpose of my program is to get error details.

我如何获得正确的 URL 是在浏览器中输入我的 URL,进行导航,正确的 URL 通常在地址栏中.另一种方法是使用链接等的属性来获取 URL.

How I get a correct URL is to type my url in a browser, navigate, and the correct URL is often in the address bar. The other way is to use Properties of a link etc to get the URL.

Microsoft.XMLHTTP 也映射到 Microsoft.XMLHTTP.1.0.HKEY_CLASSES_ROOTMsxml2.XMLHTTP 映射到 Msxml2.XMLHTTP.3.0.稍后再试

Also Microsoft.XMLHTTP maps to Microsoft.XMLHTTP.1.0. HKEY_CLASSES_ROOTMsxml2.XMLHTTP maps to Msxml2.XMLHTTP.3.0. Try a later one

用xmlhttp试试这种方式.编辑 url 等.如果它似乎工作注释掉 if/end if 转储信息,即使似乎工作.它是 vbscript 但 vbscript 在 vb6 中工作.

Try this way using xmlhttp. Edit the url's etc. If it seems to work comment out the if / end if to dump info even if seeming to work. It's vbscript but vbscript works in vb6.

 On Error Resume Next
 Set File = WScript.CreateObject("Microsoft.XMLHTTP")
 File.Open "GET", "http://www.microsoft.com/en-au/default.aspx", False
 'This is IE 8 headers
 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
 If err.number <> 0 then 
    line =""
    Line  = Line &  vbcrlf & "" 
    Line  = Line &  vbcrlf & "Error getting file" 
    Line  = Line &  vbcrlf & "==================" 
    Line  = Line &  vbcrlf & "" 
    Line  = Line &  vbcrlf & "Error " & err.number & "(0x" & hex(err.number) & ") " & err.description 
    Line  = Line &  vbcrlf & "Source " & err.source 
    Line  = Line &  vbcrlf & "" 
    Line  = Line &  vbcrlf & "HTTP Error " & File.Status & " " & File.StatusText
    Line  = Line &  vbcrlf &  File.getAllResponseHeaders
    wscript.echo Line
    Err.clear
    wscript.quit
 End If

On Error Goto 0

 Set BS = CreateObject("ADODB.Stream")
 BS.type = 1
 BS.open
 BS.Write File.ResponseBody
 BS.SaveToFile "c:users	est.txt", 2

还要看看这些其他对象是否有效.

Also see if these other objects work.

C:Users>reg query hkcr /f xmlhttp

HKEY_CLASSES_ROOTMicrosoft.XMLHTTP
HKEY_CLASSES_ROOTMicrosoft.XMLHTTP.1.0
HKEY_CLASSES_ROOTMsxml2.ServerXMLHTTP
HKEY_CLASSES_ROOTMsxml2.ServerXMLHTTP.3.0
HKEY_CLASSES_ROOTMsxml2.ServerXMLHTTP.4.0
HKEY_CLASSES_ROOTMsxml2.ServerXMLHTTP.5.0
HKEY_CLASSES_ROOTMsxml2.ServerXMLHTTP.6.0
HKEY_CLASSES_ROOTMsxml2.XMLHTTP
HKEY_CLASSES_ROOTMsxml2.XMLHTTP.3.0
HKEY_CLASSES_ROOTMsxml2.XMLHTTP.4.0
HKEY_CLASSES_ROOTMsxml2.XMLHTTP.5.0
HKEY_CLASSES_ROOTMsxml2.XMLHTTP.6.0
End of search: 12 match(es) found.

另请注意,在发生锁定之前,您可以调用任何特定 XMLHTTP 对象的次数是有限制的.如果发生这种情况,并且在调试代码时确实如此,只需更改为不同的 xmlhttp 对象

Also be aware there is a limit on how many times you can call any particular XMLHTTP object before a lockout occurs. If that happens, and it does when debugging code, just change to a different xmlhttp object

这篇关于使用 VBScript 或 Powershell 从动态链接下载文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆