【发布时间】:2015-12-24 05:15:26
【问题描述】:
我想从链接列表中下载多个文件。我找到链接的网站受到保护。这就是我想使用 IE(使用当前会话/cookie)的原因。每个链接的目标是一个 xml 文件。文件太大,无法打开然后保存。所以我需要直接保存(右键,目标另存为)。
链接列表如下所示:
<html>
<body>
<p> <a href="https://example.com/report?_hhhh=XML"Link A</a><br>> </p>
<p> <a href="https://example.com/report?_aaaa=XML"Link B</a><br>> </p>
...
</body>
</html>
我想遍历所有链接并保存每个目标。目前我有“另存为”的问题。我真的不知道该怎么做。到目前为止,这是我的代码:
Sub DownloadAllLinks()
Dim IE As Object
Dim Document As Object
Dim List As Object
Dim Link As Object
' Before I logged in to the website
Set IE = CreateObject("InternetExplorer.Application")
IE.Visible = True
IE.Navigate ("https:\\......\links.html")
Do While IE.Busy
DoEvents
Loop
' Detect all links on website
Set Document = IE.Document
Set List = Document.getElementsByTagName("a")
' Loop through all links to download them
For Each Link In List
' Now I need to automate "save target as" / right-click and then "save as"
...
Next Link
End Sub
您有什么想法可以为每个链接自动“另存为”吗?
感谢任何帮助。非常感谢, 乌力
【问题讨论】:
-
这是一个兔子洞,我已经下过很多次了。简短的回答是停止尝试让 IE 充当下载文件的代理。使用 xmlHttp 对象登录并使用 GetResponseHeader 收集/返回身份验证,然后使用 ADO 流保存文件。
-
This 可能会有所帮助。
标签: vba internet-explorer vbscript right-click save-as