找回密码
 加入
搜索
查看: 3716|回复: 14

[IE类操作] [已解决]如何在内嵌IE窗口中获取点击的链接

  [复制链接]
发表于 2017-2-20 12:31:16 | 显示全部楼层 |阅读模式
本帖最后由 jj119120 于 2017-2-22 18:57 编辑

RT  困扰很久了   搜索了一下论坛   没有太适用的方法

之前的方法是借鉴 风行者 的 内嵌IE不弹出新窗口[最新修改].au3  在点击后  等待跳转完毕 再获取当前网页链接   用sleep等待跳转完毕  时间短了获取不到   时间长了 效率十分低下   不知道有没有更好的方法

已解决  感谢各位的帮助  感谢4#提供的源码  现已解决问题   源码如下
#include <IE.au3>
#include <GUIConstantsEx.au3>
#include <WindowsConstants.au3>
#include <Misc.au3>
GUISetState()
Global $Text
$oIE = _IECreateEmbedded()
$url = "http://v.qq.com/tv/"
$dll = DllOpen("user32.dll")

$Form1 = GUICreate("Form1", 1280, 770, -1, -1)
$zhuye = GUICtrlCreateObj($oIE, 0, 0, 1280, 720)
$GUIEdit = GUICtrlCreateEdit("Test Log:" & @CRLF, 0, 725, 1280, 50)
GUISetState(@SW_SHOW)
$EventObject = ObjEvent($oIE, "IEEvent_", "DWebBrowserEvents")   ;注册获取 IE对象产生的事件,有事件则调用后面的相关函数

If @error Then
        MsgBox(0, "AutoIt COM Test", _
                        "ObjEvent: Can't use event interface 'DWebBrowserEvents'. Error code: " & Hex(@error, 8))
        Exit
EndIf

_IENavigate($oIE, $url)

While 1
        $msg = GUIGetMsg()
        If $msg = $GUI_EVENT_CLOSE Then ExitLoop

WEnd

$EventObject.Stop   ;告诉IE我们不想接收事件
$EventObject=0      ;杀死事件对象
$oIE=0              ;从内存中删除IE(不是必要的)

Func IEEvent_StatusTextChange($Text)
        GUICtrlSetData($GUIEdit, "IE Status text changed to: " & $Text & @CRLF, "append")   ;IE状态文本更改为
        If StringRegExp($Text, "http.+?\.qq\.com.+?cover\p{P}+(?<grp0>[^\.]+)\.htm", 0) = 1 Then   ;如果正则匹配
                If _IsPressed("01", $dll) Then    ;左键点击
                        MsgBox(32, "地址", $Text)
                EndIf
        EndIf
EndFunc   ;==>IEEvent_StatusTextChange
发表于 2017-2-20 14:25:29 | 显示全部楼层
新手,顶一下!
 楼主| 发表于 2017-2-20 19:30:58 | 显示全部楼层
这么多人看   一个都做不到吗   说说思路也好嘛
发表于 2017-2-20 20:19:35 | 显示全部楼层
帮助文档里,COM参考带有一示例,如下:
(注意加注中文的两个地方)
 Example script, showing the usage of COM Event functions.
; Requires at least AutoIt beta version 3.1.1.104 !
;
; See also: http://msdn.microsoft.com/workshop/browser/webbrowser/reference/objects/internetexplorer.asp

; We use a very simple GUI to show the results of our Events.
#include "GUIConstantsEx.au3"
$GUIMain=GUICreate              ( "Event Test",       600,500 )
$GUIEdit=GUICtrlCreateEdit      ( "Test Log:" & @CRLF,  10, 20, 580, 400)
$GUIProg=GUICtrlCreateProgress  (                       10,  5, 580,  10)
$GUIExit=GUICtrlCreateButton    ( " Close ",          250, 450, 80,  30)
GUISetState ()       ;Show GUI

; We prepare the Internet Explorer as our test subject
$oIE=ObjCreate("InternetExplorer.Application.1")
With $oIE
    .Visible=1
    .Top = (@DesktopHeight-400)/2
    .Height=400         ; Make it a bit smaller than our GUI.
    .Width=600
    .Silent=1           ; Don't show IE's dialog boxes
    $IEWnd=HWnd(.hWnd)  ; Remember the Window, in case user decides to close it
EndWith

; We choose for a specific Internet Explorer interface 'DWebBrowserEvents' because the IE is subject
; to modifications by e.g. Visual Studio and Adobe Acrobat Reader. If you have IE-plugins installed,
; AutoIt might not be able to find the correct interface automatically.
; 关键....注册获取 IE对象产生的事件,有事件则调用后面的相关函数
$EventObject=ObjEvent($oIE,"IEEvent_","DWebBrowserEvents")
if @error then
   Msgbox(0,"AutoIt COM Test", _
    "ObjEvent: Can't use event interface 'DWebBrowserEvents'. Error code: " & hex(@error,8))
   exit
endif

; Now starting to load an example Web page.
$URL = "http://www.AutoItScript.com/"
$oIE.Navigate( $URL )          
sleep(1000)             ; Give it some time to load the web page

GUISwitch ( $GUIMain )  ; Switch back to our GUI in case IE stealed the focus

; Waiting for user to close the GUI.
While 1
   $msg = GUIGetMsg()
   If $msg = $GUI_EVENT_CLOSE or $msg = $GUIExit Then ExitLoop
Wend

$EventObject.Stop   ; Tell IE we don't want to receive events.
$EventObject=0      ; Kill the Event Object
If WinExists($IEWnd) then $oIE.Quit     ; Close IE Window
$oIE=0              ; Remove IE from memory (not really necessary).

GUIDelete ()        ; Remove GUI

exit                ; End of our Demo.

; A few Internet Explorer Event Functions
; See also: http://msdn.microsoft.com/workshop/browser/webbrowser/reference/objects/webbrowser.asp

Func IEEvent_BeforeNavigate($URL, $Flags, $TargetFrameName, $PostData, $Headers, $Cancel)
;   Note: the declaration is different from the one on MSDN.
    GUICtrlSetData ( $GUIEdit, "BeforeNavigate: " & $URL & " Flags: " & $Flags & " tgframe: " & $TargetFrameName & " Postdat: " & $PostData & " Hdrs: " & $Headers & " canc: " & $Cancel  & @CRLF  , "append" )
EndFunc

Func IEEvent_ProgressChange($Progress,$ProgressMax)
    If $ProgressMax > 0 Then
        GUICtrlSetData($GUIProg, ($Progress * 100) / $ProgressMax )
    EndIf
EndFunc

Func IEEvent_StatusTextChange($Text)
    GUICtrlSetData ( $GUIEdit, "IE Status text changed to: " & $Text & @CRLF  , "append" )
EndFunc

Func IEEvent_PropertyChange( $szProperty)
    GUICtrlSetData ( $GUIEdit, "IE Changed the value of the property: " & $szProperty & @CRLF  , "append" )
EndFunc

Func IEEvent_DownloadComplete()
    GUICtrlSetData ( $GUIEdit, "IE has finished a navigation operation" & @CRLF  , "append" )
EndFunc
;加载链接结束
Func IEEvent_NavigateComplete($URL)  
;   Note: the declaration is different from the one on MSDN.
    GUICtrlSetData ( $GUIEdit, "IE has finished loading URL: " & $URL & @CRLF  , "append" )
EndFunc

Func IEEvent_($EventName)  
; This is an optional event function to catch non-defined events.
; The parameter contains the name of the event being called.
    GUICtrlSetData ( $GUIEdit, "Uncatched event: " & $EventName & @CRLF  , "append" )
EndFunc

评分

参与人数 1金钱 +10 收起 理由
jj119120 + 10 谢谢 头痛了好久 终于解决了

查看全部评分

发表于 2017-2-21 00:15:00 | 显示全部楼层
贴出源码看看
发表于 2017-2-21 11:23:54 | 显示全部楼层
具体网址是什么  获取哪个点击的连接
 楼主| 发表于 2017-2-21 18:14:46 | 显示全部楼层
回复 5# chamlien
#include <IE.au3>
#include <GUIConstantsEx.au3>
#include <WindowsConstants.au3>
$oIE = _IECreateEmbedded()
$url = "http://v.qq.com"
#Region ### START Koda GUI section ### Form=
$Form1 = GUICreate("Form1", 1280, 720, -1, -1)
$zhuye=GUICtrlCreateObj($oIE, 0, 0, 1280, 720)
GUISetState(@SW_SHOW)
#EndRegion ### END Koda GUI section ###
_IENavigate($oIE, $url)
While 1
        $nMsg = GUIGetMsg()
        Switch $nMsg
                Case $GUI_EVENT_CLOSE
                        Exit

        EndSwitch
WEnd
 楼主| 发表于 2017-2-21 18:26:41 | 显示全部楼层
本帖最后由 jj119120 于 2017-2-21 18:28 编辑

回复 6# 1361739590




源码在一楼   任意一个网站都行  点击网站内的链接    获取点击链接的网址

本帖子中包含更多资源

您需要 登录 才可以下载或查看,没有账号?加入

×
发表于 2017-2-21 23:03:27 | 显示全部楼层
回复 7# jj119120


    先获取全部链接,再循环_IENavigate($oIE, $url),_IENavigate默认是等待网页加载完后再执行的,不用sleep
发表于 2017-2-22 09:53:44 | 显示全部楼层
回复 8# jj119120


    你的目的中 需要打开这个点击的连接么?还是只要得到这个连接就可以了?
可以试试在点击后 不 等待跳转完毕 直接获取当前网页地址。
 楼主| 发表于 2017-2-22 18:17:26 | 显示全部楼层
回复 4# Alam


    十分感谢   问题解决了
 楼主| 发表于 2017-2-22 18:17:50 | 显示全部楼层
回复 5# chamlien


    谢谢   问题解决了   源码在一楼
 楼主| 发表于 2017-2-22 18:18:02 | 显示全部楼层
回复 10# 1361739590


    谢谢   问题解决了   源码在一楼
发表于 2017-2-24 11:29:54 | 显示全部楼层
遇到新的问题,那个左键点击事件判断是固定了,如拖动滚动条是按住了左键,如拖动时光标不小心移在链接上面就打开了链接,如何解决拖动时不打开链接的问题呢?滚动条的事件如何判断?
发表于 2017-5-9 10:57:25 | 显示全部楼层
受用了,太了不起了
您需要登录后才可以回帖 登录 | 加入

本版积分规则

QQ|手机版|小黑屋|AUTOIT CN ( 鲁ICP备19019924号-1 )谷歌 百度

GMT+8, 2024-4-23 18:13 , Processed in 0.083587 second(s), 25 queries .

Powered by Discuz! X3.5 Licensed

© 2001-2024 Discuz! Team.

快速回复 返回顶部 返回列表