【发布时间】:2017-03-27 05:06:33
【问题描述】:
我正在使用以下代码 sn-p 从网站下载 PDF 文件。
Option Explicit
Private Declare Function URLDownloadToFile Lib "urlmon" Alias "URLDownloadToFileA" _
(ByVal pCaller As Long, _
ByVal szURL As String, _
ByVal szFileName As String, _
ByVal dwReserved As Long, _
ByVal lpfnCB As Long) As Long
Sub Test()
Dim strPDFLink As String
Dim strPDFFile As String
Dim Result As Boolean
strPDFLink = "myurl?SessionKey=rCpZeX9UP300002D50BA& docid=*8G0leLEfTTX3oX8QpVUmKqRoTj6zS6bzTWf9%29Dt1hij3ym9hKqucLhtOnWVeCgM0wyGJyjI9RNj3Kv&PageNo=1"
strPDFFile = "D:\Users\d828737\Desktop\Doc Comparison\Temp\abcd.pdf"
Result = DownloadFile(strPDFLink, strPDFFile)
End Sub
Function DownloadFile(URL As String, LocalFilename As String) As Boolean
Dim lngRetVal As Long
lngRetVal = URLDownloadToFile(0, URL, LocalFilename, 0, 0)
If lngRetVal = 0 Then DownloadFile = True
End Function
Below is the response i am getting from browser using code
<html>
<head>
<META http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>Interview Enterprise Web Client</title>
</head>
<frameset name="ImageFrame" border="1" framespacing="0" topmargin="0" leftmargin="0" marginheight="0" marginwidth="0" rows="*,80">
<frame name="document" src="iv_web_client.iv_document?SessionKey=1aYT4sGK1200002D50C6&docid=*8G0SU4Fcf)xcWWX6e96)FGlOL4rOYYt0i3m)HlGth2F(W4RnxurPClkHvNBurOAsaeNfGlwBKzzTm5&outputname=&FirstPage=1&options=" scrolling="auto" border="0" frameborder="no" topmargin="0" leftmargin="0" marginheight="0" marginwidth="0" style="border-bottom:solid#000000 1px;" noresize="">
<frame name="control" src="iv_web_client.iv_doc_sel?SessionKey=1aYT4sGK1200002D50C6&docid=*8G0SU4Fcf)xcWWX6e96)FGlOL4rOYYt0i3m)HlGth2F(W4RnxurPClkHvNBurOAsaeNfGlwBKzzTm5&outputname=&pageno=1&options=" scrolling="auto" border="0" frameborder="no" topmargin="0" leftmargin="0" marginheight="0" marginwidth="0" style="border-bottom:solid#000000 1px;" noresize="">
</frameset>
<noframes>You need a frames capable browser to use this site.</noframes>
</html>
我也试过下面的方法
Set WHTTP = CreateObject("WinHTTP.WinHTTPrequest.5.1")
WHTTP.Open "GET", fileUrl, False
WHTTP.Send
FileData = WHTTP.ResponseBody
当我在浏览器中打开上述代码中给出的 url 时,我可以看到 pdf 文件自动打开。如何使用代码下载在浏览器中打开的相同 pdf 文件?
谁能帮我解决这个问题。
【问题讨论】:
-
如果删除 abcd.pdf 会发生什么?并用给出的名字运行它
-
我仍然遇到同样的错误
-
strPDFLink是本地链接吗?-