通过shell.Application返回IE的Window对象,无法获取网页中元素,请高手指点?多谢了

遇到了问题?请先进行搜索(中文和英文),然后在此提问

Moderators: tmplinshi, arcticir

gongnl
Posts: 96
Joined: 05 Jan 2015, 03:57
Location: /gongnltmp/

通过shell.Application返回IE的Window对象,无法获取网页中元素,请高手指点?多谢了

Post by gongnl » 08 Jun 2015, 23:28

使用下面的语句能新建的ie窗口,并获取网页中的元素进行填充

Code: Select all

ie := ComObjCreate("InternetExplorer.Application")
ie.Visible := True
ie.Navigate("http://mail.163.com/")
while, (IE.Readystate != 4 || IE.busy)
	Sleep, 100
ie.document.getElementById("idInput").value:="yw987258"
ie.document.getElementById("pwdInput").value:="xxxxxx"
ie.document.getElementById("loginBtn").Click()
而使用下面的语句可以在ie中新建选项卡打开mail.163.com网页,但是无法获取网页中的元素进行填充,请高手指点

Code: Select all

For pwb in ComObjCreate("Shell.Application").Windows
	if InStr(pwb.FullName, "iexplore.exe") {
		WinActivate, % "ahk_id " pwb.hwnd
		pwb.Navigate("http://mail.163.com/", 2048)
		break
	}
pwb.document.getElementById("idInput").value:="yw987258"
pwb.document.getElementById("pwdInput").value:="xxxxxx"
pwb.document.getElementById("loginBtn").Click()

gongnl
Posts: 96
Joined: 05 Jan 2015, 03:57
Location: /gongnltmp/

Re: 通过shell.Application返回IE的Window对象,无法获取网页中元素,请高手指点?多谢了

Post by gongnl » 13 Jun 2015, 06:33

经过查阅得知,通过pwb.Navigate("http://mail.163.com/", 2048)在新选项卡打开的163邮箱登录窗口,pwb不是它的对象指针,要重新获取

gongnl
Posts: 96
Joined: 05 Jan 2015, 03:57
Location: /gongnltmp/

Re: 通过shell.Application返回IE的Window对象,无法获取网页中元素,请高手指点?多谢了

Post by gongnl » 15 Jun 2015, 03:35

gongnl wrote:经过查阅得知,通过pwb.Navigate("http://mail.163.com/", 2048)在新选项卡打开的163邮箱登录窗口,pwb不是它的对象指针,要重新获取
参考一些英文网站,使用以下代码可以了

Code: Select all

For wo in ComObjCreate("Shell.Application").Windows
		if InStr(wo.FullName, "iexplore.exe") {
			WinActivate, % "ahk_id " wo.hwnd
			wo.Navigate("about:blank", 2048) ; navOpenInNewTab = 2048
			WinWaitActive, 空白页 - Windows Internet Explorer
			pwb := WBGet()
			pwb.Navigate("http://mail.163.com")
			ieload(pwb)
			break
		}

pwb.document.getElementById("idInput").value:="yw987258"
pwb.document.getElementById("pwdInput").value:="xxxxxx"
pwb.document.getElementById("loginBtn").Click()

IELoad(wb)    ;You need to send the IE handle to the function unless you define it as global.
{
	if !wb    ;If wb is not a valid pointer then quit
		return False
	Loop    ;Otherwise Sleep for .1 seconds untill the page starts loading
		Sleep,100
	until (wb.busy)
	Loop    ;Once it starts loading wait until completes
		Sleep,100
	until (!wb.busy)
	Loop    ;optional check to wait for the page to completely load
		Sleep,100
	until (wb.Document.Readystate = "Complete")
	return True
}

WBGet(WinTitle="ahk_class IEFrame", Svr#=1) {               ;// based on ComObjQuery docs
   static msg := DllCall("RegisterWindowMessage", "str", "WM_HTML_GETOBJECT")
        , IID := "{0002DF05-0000-0000-C000-000000000046}"   ;// IID_IWebBrowserApp
;//     , IID := "{332C4427-26CB-11D0-B483-00C04FD90119}"   ;// IID_IHTMLWindow2
   SendMessage msg, 0, 0, Internet Explorer_Server%Svr#%, %WinTitle%
   if (ErrorLevel != "FAIL") {
      lResult:=ErrorLevel, VarSetCapacity(GUID,16,0)
      if DllCall("ole32\CLSIDFromString", "wstr","{332C4425-26CB-11D0-B483-00C04FD90119}", "ptr",&GUID) >= 0 {
         DllCall("oleacc\ObjectFromLresult", "ptr",lResult, "ptr",&GUID, "ptr",0, "ptr*",pdoc)
         return ComObj(9,ComObjQuery(pdoc,IID,IID),1), ObjRelease(pdoc)
      }
   }
}

gdqb521
Posts: 13
Joined: 15 Aug 2015, 08:01

Re: 通过shell.Application返回IE的Window对象,无法获取网页中元素,请高手指点?多谢了

Post by gdqb521 » 15 Aug 2015, 10:17

柳暗花明又一村啊,我近期就在找这个,回头测试,我用win10好像兼容不是太好。

Post Reply

Return to “请求帮助”