IE浏览器下载文件时,如何提取URL地址?

Posted

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了IE浏览器下载文件时,如何提取URL地址?相关的知识,希望对你有一定的参考价值。

IE浏览器下载文件时,一般直接弹出下载对话框。
如图:

这时也可以用迅雷,快车等监视,但也不能监视的时候。这是如果要能提取URL就可以用迅雷等下载了。

问题是如何提取URL?
有的链接是图片,右键后没有在新窗口打开可选。
iambike 说的方法也没有找到下载地址。有的网页如CSDN的源文件才几行字。
CSDN的下载都是这种情况!!!!!!!

    打开IE

    开始下载任务

    按Ctrl+J打开下载管理

    选中下载任务,右键点击【复制下载链接】即可

参考技术A 查看源代码,有时图片连接的是下载地址,所以点图片就直接下载了,右键属性看到的也只是图片的地址而已,查看源代码,找到图片的连接地址,就是下载地址了,呵呵

贴上网页地址,我看看怎么回事,源代码应该能的本回答被提问者采纳
参考技术B 邮件属性 参考技术C 下载连接那里点右键在新窗口中打开

VB 编写的OCX 如何取得当前页面的URL,必须兼容所有IE内核的浏览器(如360浏览器)

页面加载时,我已通过GetActiveWindow()获取到该窗口的句柄.

在IE浏览器下面:
我通过ShelllWindows的Document.URL已经取得了所有的地址,再通过对象的hwnd与GetActiveWindow()判断是不是当前窗口,并正常可以取得地址.

可是在360浏览器下面,却报错了(方法'~'作用于对象'~'失败)。具体原因就是对象的hwnd这句话不能执行。

请问,基于IE内核的浏览器,该如何正确的获取当前窗口的URL?谢谢
ActID = GetActiveWindow() Dim mShellWindow As New SHDocVw.ShellWindows '循环变量 For i = 0 To mShellWindow.Count - 1 If VBA.TypeName(mShellWindow.Item(i).Document) = "HTMLDocument" Then hw = mShellWindow.Item(i).hwnd '在360下面报错 if hw=ActID then MsgBox mShellWindow.Item(i).Document.URL exit for end if End If Next i 报错:方法'~'作用于对象'~'失败 请问大家,如何才能正确的获取IE内核的浏览器的URL? 请不要把网上的一些东西贴出来,因为我已经找遍了网上的东西,并已加也测试,都无法通过。必须得亲自测试后,然后告诉,经我测试成功后,追加100-300分!

*******************************************************************************
已解决,原来如此简单,奶奶的,害得我想了N多办法。一代码就可以搞定了!

此题本人已经解决了,目前只供大家讨论和研究,到时候我会选取一个最佳的答案.
我解决是一句代码就搞定了!

参考技术A 以下代码在360浏览器下调试成功。分两步:一、把下面代码复制到一个模块中:Option ExplicitDeclare Function FindWindowEx Lib "user32" Alias "FindWindowExA" (ByVal hWnd1 As Long, ByVal hWnd2 As Long, ByVal lpsz1 As String, ByVal lpsz2 As String) As LongPublic Declare Function SetCapture Lib "user32" (ByVal hWnd As Long) As LongPublic Declare Function GetCursorPos Lib "user32" (lpPoint As PointAPI) As LongPublic Declare Function WindowFromPoint Lib "user32" (ByVal xPoint As Long, ByVal yPoint As Long) As LongPublic Declare Function ScreenToClient Lib "user32" (ByVal hWnd As Long, lpPoint As PointAPI) As LongType PointAPI x As Long Y As LongEnd TypePrivate Type UUID Data1 As Long Data2 As Integer Data3 As Integer Data4(0 To 7) As ByteEnd TypePrivate Declare Function GetClassName Lib "user32" _ Alias "GetClassNameA" ( _ ByVal hWnd As Long, _ ByVal lpClassName As String, _ ByVal nMaxCount As Long) As LongPrivate Declare Function EnumChildWindows Lib "user32" ( _ ByVal hWndParent As Long, _ ByVal lpEnumFunc As Long, _ lParam As Long) As LongPrivate Declare Function RegisterWindowMessage Lib "user32" _ Alias "RegisterWindowMessageA" ( _ ByVal lpString As String) As LongPrivate Declare Function SendMessageTimeout Lib "user32" _ Alias "SendMessageTimeoutA" ( _ ByVal hWnd As Long, _ ByVal msg As Long, _ ByVal wParam As Long, _ lParam As Any, _ ByVal fuFlags As Long, _ ByVal uTimeout As Long, _ lpdwResult As Long) As LongPrivate Const SMTO_ABORTIFHUNG = &H2Private Declare Function ObjectFromLresult Lib "oleacc" ( _ ByVal lResult As Long, _ riid As UUID, _ ByVal wParam As Long, _ ppvObject As Any) As LongPrivate Declare Function FindWindow Lib "user32" _ Alias "FindWindowA" ( _ ByVal lpClassName As String, _ ByVal lpWindowName As String) As Long'Function IEDOMFromhWnd(ByVal hWnd As Long) As IHTMLDocumentDim IID_IHTMLDocument As UUIDDim hWndChild As LongDim lRes As LongDim lMsg As LongDim hr As Long If hWnd <> 0 Then If Not IsIEServerWindow(hWnd) Then ' Find a child IE server window EnumChildWindows hWnd, AddressOf EnumChildProc, hWnd End If If hWnd <> 0 Then ' Register the message lMsg = RegisterWindowMessage("WM_HTML_GETOBJECT") ' Get the object pointer Call SendMessageTimeout(hWnd, lMsg, 0, 0, _ SMTO_ABORTIFHUNG, 1000, lRes) If lRes Then ' Initialize the interface ID With IID_IHTMLDocument .Data1 = &H626FC520 .Data2 = &HA41E .Data3 = &H11CF .Data4(0) = &HA7 .Data4(1) = &H31 .Data4(2) = &H0 .Data4(3) = &HA0 .Data4(4) = &HC9 .Data4(5) = &H8 .Data4(6) = &H26 .Data4(7) = &H37 End With ' Get the object from lRes hr = ObjectFromLresult(lRes, IID_IHTMLDocument, _ 0, IEDOMFromhWnd) End If End If End IfEnd FunctionPrivate Function IsIEServerWindow(ByVal hWnd As Long) As BooleanDim lRes As LongDim sClassname As String sClassname = String$(100, 0) lRes = GetClassName(hWnd, sClassname, Len(sClassname)) sClassname = Left$(sClassname, lRes) IsIEServerWindow = StrComp(sClassname, _ "Internet Explorer_Server", _ vbTextCompare) = 0End Function'Function EnumChildProc(ByVal hWnd As Long, lParam As Long) As Long If IsIEServerWindow(hWnd) Then lParam = hWnd Else EnumChildProc = 1 End IfEnd Function二、建立一个窗体,加入按钮command1,并复制下面代码:Private Sub Command1_Click()Dim doc, wnd As Longwnd = FindWindow("360se5_Frame", vbNullString)wnd = FindWindowEx(wnd, 0, "SeWnd", vbNullString)wnd = FindWindowEx(wnd, 0, "XWnd", vbNullString)wnd = FindWindowEx(wnd, 0, "Container", vbNullString)wnd = FindWindowEx(wnd, 0, "Shell Embedding", vbNullString)wnd = FindWindowEx(wnd, 0, "Shell DocObject View", vbNullString)wnd = FindWindowEx(wnd, 0, "Internet Explorer_Server", vbNullString)Set doc = IEDOMFromhWnd(wnd)MsgBox "360浏览器当前的网址是:" & doc.URLEnd Sub三、打开360浏览器,随便浏览某个网址。然后运行本程序,点击command1按钮,Ok! 参考技术B 其实不用那么复杂,在ocx加个timer,Private Sub Timer1_Timer()
Dim oShellApp, oShellAppWindows, oWin
Dim URL As String
Set oShellApp = CreateObject("Shell.Application")
Set oShellAppWindows = oShellApp.Windows
For Each oWin In oShellAppWindows
If LCase(TypeName(oWin.Document)) = "htmldocument" Then
URL = oWin.LocationURL

End If
Next
End Sub

以上是关于IE浏览器下载文件时,如何提取URL地址?的主要内容,如果未能解决你的问题,请参考以下文章

弹出文件下载窗口时如何提取文件下载的URL?

如何使用URL地址下载东西

ie打开本地链接的一个wav文件时,无法打开

问题:解决上传文件IE浏览器弹出下载框bug?

如何让 IE 以外的浏览器接受文件 url?

IE浏览器下载文件保存时提示:“你没有权限在此位置中保存文件”解决办法