最近用迅雷,右键选择“使用迅雷下载全部链接”,会有一个可视化框方式进行下载的选择框:
点击“是”之后,就会进行像qq截图的区域选择。迅雷可以将这个区域里面的链接提取出来,然后全部下载下来。
这种方式确实比较有用,我比较关心这是如何实现的?
在注册表“HKEY_CURRENT_USER/Software/Microsoft/Internet Explorer/MenuExt/使用迅雷下载全部链接”下面,显示处理“使用迅雷下载全部链接”,的url是e:/Program Files/Thunder Network/Thunder/Program/GetAllUrl.htm,文件内容如下:
<script language="VBScript">
Sub OnContextMenu()
set ThunderAgent = CreateObject("ThunderAgent.Agent.1")
If ThunderAgent.ConfirmRectMode = 0 Then
set links = external.menuArguments.document.links
set images = external.menuArguments.document.images
link_count = links.length
image_count = images.length
strDownloadPage = external.menuArguments.document.url
set theDownloadPage = external.menuArguments.document.getElementById("thunder_down_pageurl")
if TypeName(theDownloadPage) <> "Nothing" then
strDownloadPage = theDownloadPage.value
end if
strStatPage = ""
set theStatPage = external.menuArguments.document.getElementById("thunder_stat_pageurl")
if TypeName(theStatPage) <> "Nothing" then
strStatPage = theStatPage.value
end if
if strStatPage <> "" then
for i = 0 to link_count-1
call ThunderAgent.AddTask4(links(i).href, "", "", links(i).innerText, strDownloadPage, -1, 0, -1, external.menuArguments.document.cookie, "", strStatPage)
next
for i = 0 to image_count-1
call ThunderAgent.AddTask4(images(i).src, "", "", images(i).innerText, strDownloadPage, -1, 0, -1, external.menuArguments.document.cookie, "", strStatPage)
next
else
for i = 0 to link_count-1
call ThunderAgent.AddTask4(links(i).href, "", "", links(i).innerText, strDownloadPage, -1, 0, -1, external.menuArguments.document.cookie, "", "")
next
for i = 0 to image_count-1
call ThunderAgent.AddTask4(images(i).src, "", "", images(i).innerText, strDownloadPage, -1, 0, -1, external.menuArguments.document.cookie, "", "")
next
end if
call ThunderAgent.CommitTasks2(1)
Else
ThunderAgent.AddTaskInRect()
End If
set ThunderAgent = nothing
end sub
call OnContextMenu()
</script>
通过set ThunderAgent = CreateObject("ThunderAgent.Agent.1") ,我们知道这个脚本是调用activex控制来和迅雷主程序打交道的。ThunderAgent.Agent.1是ProgID,通过查注册表HKEY_CLASSES_ROOT/ThunderAgent.Agent.1可以知道其对应的CLSID为{485463B7-8FB2-4B3B-B29B-8B919B0EACCE}。然后到HKEY_CLASSES_ROOT/CLSID/{485463B7-8FB2-4B3B-B29B-8B919B0EACCE}/InprocServer32下面我们可以知道这个activex对应的dll为e:/Program Files/Thunder Network/Thunder/ComDlls/ThunderAgent5.9.23.1488.dll。然后我们通过vs提供的oleview.exe来查看这个dll的接口信息(typelib),其实就是解析dll的typelib资源段。
// Generated .IDL file (by the OLE/COM Object Viewer) // // typelib filename: ThunderAgent5.9.23.1488.dll[ uuid(26D657AE-A466-4F44-AB1D-5CFFFADBED97), version(1.0), helpstring("ThunderAgent 1.0 Type Library"), custom(DE77BA64-517C-11D1-A2DA-0000F8773CE9, 100663657), custom(DE77BA63-517C-11D1-A2DA-0000F8773CE9, 1277990859), custom(DE77BA65-517C-11D1-A2DA-0000F8773CE9, "Created by MIDL version 6.00.0361 at Thu Jul 01 21:27:29 2010 ")] library THUNDERAGENTLib { // TLib : // TLib : OLE Automation : {00020430-0000-0000-C000-000000000046} importlib("stdole2.tlb"); // Forward declare all types defined in this typelib interface IAgent; interface IAgent2; interface IAgent3; interface IAgent4; interface IAgent5; interface IAgent6; interface IXunLeiAgent; [ uuid(485463B7-8FB2-4B3B-B29B-8B919B0EACCE), helpstring("Thunder Agent Class") ] coclass Agent { [default] interface IAgent; interface IAgent2; interface IAgent3; interface IAgent4; interface IAgent5; interface IAgent6; }; [ odl, uuid(1622F56A-0C55-464C-B472-377845DEF21D), helpstring("Thunder IAgent Interface"), dual, oleautomation ] interface IAgent : IDispatch { [id(0x00000001), helpstring("method GetInfo")] HRESULT GetInfo( [in] BSTR pInfoName, [out, retval] BSTR* ppResult); [id(0x00000002), helpstring("method AddTask")] HRESULT AddTask( [in] BSTR pURL, [in, optional, defaultvalue("")] BSTR pFileName, [in, optional, defaultvalue("")] BSTR pPath, [in, optional, defaultvalue("")] BSTR pComments, [in, optional, defaultvalue("")] BSTR pReferURL, [in, optional, defaultvalue(-1)] int nStartMode, [in, optional, defaultvalue(0)] int nOnlyFromOrigin, [in, optional, defaultvalue(-1)] int nOriginThreadCount); [id(0x00000003), helpstring("method CommitTasks")] HRESULT CommitTasks([out, retval] int* pResult); [id(0x00000004), helpstring("method CancelTasks")] HRESULT CancelTasks(); [id(0x00000005), helpstring("method GetTaskInfo")] HRESULT GetTaskInfo( [in] BSTR pURL, [in] BSTR pInfoName, [out, retval] BSTR* ppResult); [id(0x00000006), helpstring("method GetInfoStruct")] HRESULT GetInfoStruct([in] int pInfo); [id(0x00000007), helpstring("method GetTaskInfoStruct")] HRESULT GetTaskInfoStruct([in] int pTaskInfo); }; [ odl, uuid(1ADEFB0D-0FFA-4470-8AB0-B921080F0642), helpstring("Thunder IAgent2 Interface"), dual, oleautomation ] interface IAgent2 : IAgent { [id(0x00000008), helpstring("method AddTask2")] HRESULT AddTask2( [in] BSTR pURL, [in, optional, defaultvalue("")] BSTR pFileName, [in, optional, defaultvalue("")] BSTR pPath, [in, optional, defaultvalue("")] BSTR pComments, [in, optional, defaultvalue("")] BSTR pReferURL, [in, optional, defaultvalue(-1)] int nStartMode, [in, optional, defaultvalue(0)] int nOnlyFromOrigin, [in, optional, defaultvalue(-1)] int nOriginThreadCount, [in, optional, defaultvalue("")] BSTR pCookie); [id(0x00000009), helpstring("method CommitTasks2")] HRESULT CommitTasks2( [in] int nIsAsync, [out, retval] int* pResult); }; [ odl, uuid(18243D84-9FE5-4977-9247-1AE41355C5C3), helpstring("Thunder IAgent3 Interface"), dual, oleautomation ] interface IAgent3 : IAgent2 { [id(0x0000000a), helpstring("method AddTask3")] HRESULT AddTask3( [in] BSTR pURL, [in, optional, defaultvalue("")] BSTR pFileName, [in, optional, defaultvalue("")] BSTR pPath, [in, optional, defaultvalue("")] BSTR pComments, [in, optional, defaultvalue("")] BSTR pReferURL, [in, optional, defaultvalue(-1)] int nStartMode, [in, optional, defaultvalue(0)] int nOnlyFromOrigin, [in, optional, defaultvalue(-1)] int nOriginThreadCount, [in, optional, defaultvalue("")] BSTR pCookie, [in, optional, defaultvalue("")] BSTR pCID); }; [ odl, uuid(D3830C5B-62EA-48EF-A7CB-5B3944CAE12F), helpstring("Thunder IAgent4 Interface"), dual, oleautomation ] interface IAgent4 : IAgent3 { [id(0x0000000b), helpstring("method AddTask4")] HRESULT AddTask4( [in] BSTR pURL, [in, optional, defaultvalue("")] BSTR pFileName, [in, optional, defaultvalue("")] BSTR pPath, [in, optional, defaultvalue("")] BSTR pComments, [in, optional, defaultvalue("")] BSTR pReferURL, [in, optional, defaultvalue(-1)] int nStartMode, [in, optional, defaultvalue(0)] int nOnlyFromOrigin, [in, optional, defaultvalue(-1)] int nOriginThreadCount, [in, optional, defaultvalue("")] BSTR pCookie, [in, optional, defaultvalue("")] BSTR pCID, [in, optional, defaultvalue("")] BSTR pStatURL); }; [ odl, uuid(80BB764D-348B-48EA-9F0F-D9458E0EE186), helpstring("Thunder IAgent5 Interface"), dual, oleautomation ] interface IAgent5 : IAgent4 { [id(0x0000000c), helpstring("method AddTask5")] HRESULT AddTask5( [in] BSTR pURL, [in, optional, defaultvalue("")] BSTR pFileName, [in, optional, defaultvalue("")] BSTR pPath, [in, optional, defaultvalue("")] BSTR pComments, [in, optional, defaultvalue("")] BSTR pReferURL, [in, optional, defaultvalue(-1)] int nStartMode, [in, optional, defaultvalue(0)] int nOnlyFromOrigin, [in, optional, defaultvalue(-1)] int nOriginThreadCount, [in, optional, defaultvalue("")] BSTR pCookie, [in, optional, defaultvalue("")] BSTR pCID, [in, optional, defaultvalue("")] BSTR pStatURL, [in, optional, defaultvalue(-1)] int nCallType, [in, optional, defaultvalue("")] BSTR pGCID, [in, optional, defaultvalue(-1)] int nFileSize); [id(0x0000000d), helpstring("根据指定的迅雷类型启动迅雷")] HRESULT CommitTasks3( [in] int nThunderType, [in] int nIsAsync, [out, retval] int* pResult); }; [ odl, uuid(6BEC8438-4AEB-4EE9-9385-3C9F0F11F47D), helpstring("Thunder IAgent6 Interface"), dual, oleautomation ] interface IAgent6 : IAgent5 { [id(0x0000000e), helpstring("method ConfirmRectMode")] HRESULT ConfirmRectMode([out, retval] int* pResult); [id(0x0000000f), helpstring("method AddTaskInRect")] HRESULT AddTaskInRect(); }; [ uuid(E1A931EB-13B6-40B9-BEE9-3B98CC8A8DF8), helpstring("XunLeiAgent Class") ] coclass XunLeiAgent { [default] interface IXunLeiAgent; }; [ odl, uuid(3E9DE0FB-FFA0-4954-A514-1D7712559E35), helpstring("IXunLeiAgent 接口"), dual, nonextensible, oleautomation ] interface IXunLeiAgent : IDispatch { }; };
getAllurl.htm用到的方法有ConfirmRectMode,AddTask4,CommitTasks2和AddTaskInRect。ConfirmRectMode的作用就是弹出是否用可视化下载的对话框;AddTask4的作用是将链接加入列表(传入了cookie:external.menuArguments.document.cookie,这也是为什么迅雷可以下载需要登录的连接的原因);CommitTasks2的作用是让迅雷开始下载;AddTaskInRect的作用是进入可视化下载界面。
如果用户选择的是非可视化下载,通过external.menuArguments.document.links和external.menuArguments.document.images 就可以拿到当前页面的所有链接和图片地址。external的接口可以看http://msdn.microsoft.com/en-us/library/ms535246(v=VS.85).aspx。
那接下来的关键就是AddTaskInRect方法的实现了。vckbase上有一篇文章《采集网页选定部分全攻略》,介绍了如何获取选定部分文字和图片,我估计迅雷的实现跟这个差不多。
参考链接:
http://www.cnblogs.com/waxdoll/archive/2005/12/23/303470.html
http://blog.csdn.net/xushiweizh/archive/2007/04/26/1585137.aspx
http://topic.csdn.net/t/20060921/16/5038787.html
http://zhidao.baidu.com/question/11153472
http://www.vbaccelerator.com/progid.htm
http://forums.devx.com/archive/index.php/t-90027.html
http://www.codeproject.com/KB/aspnet/externalmenuArgument.aspx
再分享一下我老师大神的人工智能教程吧。零基础!通俗易懂!风趣幽默!还带黄段子!希望你也加入到我们人工智能的队伍中来!https://blog.csdn.net/jiangjunshow