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

查看:122
本文介绍了使用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脚本?

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.

感谢您的帮助。

推荐答案

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

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。

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_ROOT\Msxml2.XMLHTTP映射到Msxml2.XMLHTTP.3.0。尝试以后一个

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

尝试这样使用xmlhttp。编辑url的等。如果似乎工作注释if / end如果转储信息,即使看起来工作。它是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\test.txt", 2

还可以看看这些其他对象是否可行。

Also see if these other objects work.

C:\Users>reg query hkcr /f xmlhttp

HKEY_CLASSES_ROOT\Microsoft.XMLHTTP
HKEY_CLASSES_ROOT\Microsoft.XMLHTTP.1.0
HKEY_CLASSES_ROOT\Msxml2.ServerXMLHTTP
HKEY_CLASSES_ROOT\Msxml2.ServerXMLHTTP.3.0
HKEY_CLASSES_ROOT\Msxml2.ServerXMLHTTP.4.0
HKEY_CLASSES_ROOT\Msxml2.ServerXMLHTTP.5.0
HKEY_CLASSES_ROOT\Msxml2.ServerXMLHTTP.6.0
HKEY_CLASSES_ROOT\Msxml2.XMLHTTP
HKEY_CLASSES_ROOT\Msxml2.XMLHTTP.3.0
HKEY_CLASSES_ROOT\Msxml2.XMLHTTP.4.0
HKEY_CLASSES_ROOT\Msxml2.XMLHTTP.5.0
HKEY_CLASSES_ROOT\Msxml2.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天全站免登陆