1 (изменено: inseption86, 2018-10-28 15:57:51)

Тема: AHK: IE COM Multi URL

Добрый день! Подскажите пож-та, имеются несколько сайтов для работы, возможно ли их разграничить по "ie.document.getElementsByTagName("input")[2].value", не знаю, как правильно объяснить, может пример поможет:



ie := ComObjCreate("InternetExplorer.Application")
ie.Visible := true
ie.Navigate("https://1.com")
ie.Navigate("https://2.com,2048)
ie.Navigate("https://3.com",2048)
ie.Navigate("https://4.com",2048)
while ie.readystate <> 4
	continue
sleep 100

;https://1.com
msgbox % ie.document.getElementsByTagName("input")[2].value

;https://2.com
msgbox % ie.document.getElementsByTagName("input")[2].value 

;https://3.com
msgbox % ie.document.getElementsByTagName("input")[2].value 

;https://4.com

msgbox % ie.document.getElementsByTagName("input")[2].value 

2 (изменено: teadrinker, 2018-10-28 22:18:26)

Re: AHK: IE COM Multi URL

Каждая страница, открытая в новой вкладке, имеет свой отдельный объект InternetExplorer; чтобы работать с новой вкладкой, нужно получить связанный с ней объект. Например, можно вот так по url:

ieArr := []
ie := ComObjCreate("InternetExplorer.Application")
ieArr.Push(ie)
OnExit( Func("IeQuit").Bind(ieArr) )
ie.Visible := true

ie.Navigate("https://autohotkey.com/boards/index.php?style=17")
ie.Navigate("http://forum.script-coding.com/viewtopic.php?pid=129526#p129526", 2048)
while ie.busy
   continue

ie2 := WBFromUrl(ie.hwnd, "http://forum.script-coding.com/viewtopic.php?pid=129526#p129526")
ieArr.Push(ie2)

codeBoxes := ie2.document.getElementsByTagName("code")
MsgBox,, My Code, % codeBoxes[1].innerHtml

WBFromUrl(hWndIE, url)  {
   static VT_DISPATCH := 9, F_OWNVALUE := 1
        , IID_IWebBrowserApp := "{0002DF05-0000-0000-C000-000000000046}"
        
   for window in ComObjCreate("Shell.Application").Windows  {
      if (window.hwnd = hWndIE && window.document.parentWindow.location.href = url) {
         doc := window.document
         break
      }
   }
   pdoc := ComObjUnwrap(doc)
   oWb := ComObject(VT_DISPATCH, ComObjQuery(pdoc, IID_IWebBrowserApp, IID_IWebBrowserApp), F_OWNVALUE)
   ObjRelease(pdoc)
   Return oWb
}

IeQuit(arr)  {
   for k, ie in arr
      try ie.Quit()
}
Разработка AHK-скриптов:
e-mail dfiveg@mail.ru
Telegram jollycoder

3

Re: AHK: IE COM Multi URL

Как-то сложно.

shell := ComObjCreate("Shell.Application")

ie := ComObjCreate("InternetExplorer.Application")
ie.Visible := true
ie.Navigate("https://1.com")
ie.Navigate("https://2.com",2048)
ie.Navigate("https://2.com/?test",2048)
loop
{
   for window in shell.Windows
   {
      if (window.LocationUrl = "https://2.com/?test")
      {
         ie2 := window
         break 2
      }
   }
}
ie2.Navigate("google.com")

4

Re: AHK: IE COM Multi URL

Ну, можно и так, слегка перемудрил

Разработка AHK-скриптов:
e-mail dfiveg@mail.ru
Telegram jollycoder

5

Re: AHK: IE COM Multi URL

Всем спасибо! Завтра попробую.

6 (изменено: inseption86, 2018-10-29 11:23:09)

Re: AHK: IE COM Multi URL

Добрый день! Что то я туговат и не разобрался.
Мой код:


#NoEnv  ; Recommended for performance and compatibility with future AutoHotkey releases.
; #Warn  ; Enable warnings to assist with detecting common errors.
SendMode Input  ; Recommended for new scripts due to its superior speed and reliability.
SetWorkingDir %A_ScriptDir%  ; Ensures a consistent starting directory.
#SingleInstance force   ; игнор уже запущенного скрипта, переоткрытие

FileSelectFile, Path, 3, , Open Excel File, Excel File (*.xls; *.xlsx)
IF path =
	ExitApp
Xl := ComObjCreate("Excel.Application")
Xl.Visible := true
Xl.Workbooks.Open(Path)

FormatTime, TimeString, , dd.MM.yyyy
Xl.Range("A1").value := Xl.Range("A1").value " " Timestring
Xl.Range("B1").value := Xl.Range("B1").value " " Timestring
Xl.Range("C1").value := Xl.Range("C1").value " " Timestring
Xl.Range("D1").value := Xl.Range("D1").value " " Timestring

ie := ComObjCreate("InternetExplorer.Application")
ie.Visible := true
ie.Navigate("https://1.ru")
ie.Navigate("https://2.ru",2048)
ie.Navigate("http://3",2048)
ie.Navigate("http://4",2048)

while ie.readystate <> 4
	continue

Gui, +ToolWindow +AlwaysOnTop 

Gui, Font, s12 italic 

Gui, Add, text,x30, 1
Gui, Add, text,x+60, 2
Gui, Add, text,x+65, 3
Gui, Add, text,x+70, 4
Gui, Font,  normal

Gui, Add, Button, -TabStop x5 y+10 w40 h40 g11, +


Gui, Add, Button, -TabStop x+40 y+-40 w40 h40 g21, +


Gui, Add, Button, -TabStop x+40 y+-40 w40 h40 g31 , +


Gui, Add, Button, -TabStop x+40 y+-40 w40 h40 g41 , +

Gui, Show, x600 y100 w300 h110, Proverka
Return



; здесь "https://1.ru"
g11:
xl.Worksheets("Лист").Cells.(xl.Worksheets("Лист").Cells.(xl.Worksheets("Лист").Rows.Count, "A").End(xlUp := -4162).Row + 1, "A").value:= ie.document.getElementsByTagName("input")[2].value 

; здесь "https://2.ru"
g21:
xl.Worksheets("Лист").Cells.(xl.Worksheets("Лист").Cells.(xl.Worksheets("Лист").Rows.Count, B").End(xlUp := -4162).Row + 1, "B").value:= ie.document.getElementsByTagName("input")[0].value

; здесь "https://3.ru"
g31:
xl.Worksheets("Лист").Cells.(xl.Worksheets("Лист").Cells.(xl.Worksheets("Лист").Rows.Count, C").End(xlUp := -4162).Row + 1, "C").value:= ie.document.getElementsByTagName("input")[0].value

; здесь "https://4.ru"
g41:
xl.Worksheets("Лист").Cells.(xl.Worksheets("Лист").Cells.(xl.Worksheets("Лист").Rows.Count, D").End(xlUp := -4162).Row + 1, "D").value:= ie.document.getElementsByTagName("input")[1].value

Еще проблема в том, что, например, ie.Navigate("https://2.ru",2048) - не выполянется ".....value:= ie.document.getElementsByTagName("input")[0].value", если убрать "2048", то всё ОК

7 (изменено: teadrinker, 2018-10-29 13:37:25)

Re: AHK: IE COM Multi URL

Вам нужно для каждого url, открытого в новой вкладке, получить свой объект IE, как в примере ниже для вкладки с адресом этой страницы:

ieArr := []
ie := ComObjCreate("InternetExplorer.Application")
ieArr.Push(ie)
OnExit( Func("IeQuit").Bind(ieArr) )
ie.Visible := true

ie.Navigate("https://autohotkey.com/boards/index.php?style=17")
ie.Navigate("http://forum.script-coding.com/viewtopic.php?pid=129526#p129526", 2048)

; получаем объект IE для новой вкладки
ie2 := WBFromUrl("http://forum.script-coding.com/viewtopic.php?pid=129526#p129526")
ieArr.Push(ie2)
; для получения информации с новой вкладки используем соответствующий ей объект IE
codeBoxes := ie2.document.getElementsByTagName("code")
MsgBox,, My Code, % codeBoxes[4].innerHtml

WBFromUrl(url)  {
   shell := ComObjCreate("Shell.Application")
   loop  {
      for window in shell.Windows  {
         if (window.LocationUrl = url)
            break 2
      }
      Sleep 10
   }
   Return window
}

IeQuit(arr)  {
   for k, ie in arr
      try ie.Quit()
}
inseption86 пишет:

ie.Navigate("https://2.ru",2048) - не выполянется

Ну, открывайте этот url в основной вкладке.

Разработка AHK-скриптов:
e-mail dfiveg@mail.ru
Telegram jollycoder

8

Re: AHK: IE COM Multi URL

teadrinker
Спасибо большое! Вроде бы вот так:


#NoEnv  ; Recommended for performance and compatibility with future AutoHotkey releases.
; #Warn  ; Enable warnings to assist with detecting common errors.
SendMode Input  ; Recommended for new scripts due to its superior speed and reliability.
SetWorkingDir %A_ScriptDir%  ; Ensures a consistent starting directory.
#SingleInstance force   ; игнор уже запущенного скрипта, переоткрытие

FileSelectFile, Path, 3, , Open Excel File, Excel File (*.xls; *.xlsx)
IF path =
	ExitApp
Xl := ComObjCreate("Excel.Application")
Xl.Visible := true
Xl.Workbooks.Open(Path)

FormatTime, TimeString, , dd.MM.yyyy
Xl.Range("A1").value := Xl.Range("A1").value " " Timestring
Xl.Range("B1").value := Xl.Range("B1").value " " Timestring
Xl.Range("C1").value := Xl.Range("C1").value " " Timestring
Xl.Range("D1").value := Xl.Range("D1").value " " Timestring

ieArr := []
ie := ComObjCreate("InternetExplorer.Application")
ieArr.Push(ie)
ie.Visible := true

ie.Navigate("https://1.ru")
ie.Navigate("https://2.ru",2048)
ie.Navigate("http://3",2048)
ie.Navigate("http://4",2048)



Gui, +ToolWindow +AlwaysOnTop 

Gui, Font, s12 italic 

Gui, Add, text,x30, 1
Gui, Add, text,x+60, 2
Gui, Add, text,x+65, 3
Gui, Add, text,x+70, 4
Gui, Font,  normal

Gui, Add, Button, -TabStop x5 y+10 w40 h40 g11, +


Gui, Add, Button, -TabStop x+40 y+-40 w40 h40 g21, +


Gui, Add, Button, -TabStop x+40 y+-40 w40 h40 g31 , +


Gui, Add, Button, -TabStop x+40 y+-40 w40 h40 g41 , +

Gui, Show, x600 y100 w300 h110, Proverka
Return



; здесь "https://1.ru"
g11:

ie := WBFromUrl("https://1.ru")
ieArr.Push(ie)

xl.Worksheets("Лист").Cells.(xl.Worksheets("Лист").Cells.(xl.Worksheets("Лист").Rows.Count, "A").End(xlUp := -4162).Row + 1, "A").value:= ie.document.getElementsByTagName("input")[2].value 

; здесь "https://2.ru"
g21:

ie2 := WBFromUrl("https://2.ru")
ieArr.Push(ie2)

xl.Worksheets("Лист").Cells.(xl.Worksheets("Лист").Cells.(xl.Worksheets("Лист").Rows.Count, B").End(xlUp := -4162).Row + 1, "B").value:= ie2.document.getElementsByTagName("input")[0].value

; здесь "https://3.ru"
g31:

ie3 := WBFromUrl("https://3.ru")
ieArr.Push(ie3)

xl.Worksheets("Лист").Cells.(xl.Worksheets("Лист").Cells.(xl.Worksheets("Лист").Rows.Count, C").End(xlUp := -4162).Row + 1, "C").value:= ie3.document.getElementsByTagName("input")[0].value

; здесь "https://4.ru"
g41:

ie4 := WBFromUrl("https://4.ru")
ieArr.Push(ie4)

xl.Worksheets("Лист").Cells.(xl.Worksheets("Лист").Cells.(xl.Worksheets("Лист").Rows.Count, D").End(xlUp := -4162).Row + 1, "D").value:= ie.document.getElementsByTagName("input")[1].value


WBFromUrl(url)  {
   shell := ComObjCreate("Shell.Application")
   loop  {
      for window in shell.Windows  {
         if (window.LocationUrl = url)
            break 2
      }
      Sleep 10
   }
   Return window
}



9

Re: AHK: IE COM Multi URL

Если не используете OnExit, то в ieArr.Push(ie) смысла нет.

Разработка AHK-скриптов:
e-mail dfiveg@mail.ru
Telegram jollycoder

10

Re: AHK: IE COM Multi URL

inseption86, а есть ли вообще смысл для вашей задачи использовать IE?

11

Re: AHK: IE COM Multi URL

Malcev

Скорее всего, да, т.к. идёт ручной поиск в 4-х базах, после чего найденный результат нужно заносить в excel для отчётности

12

Re: AHK: IE COM Multi URL

Наверняка можно получать результаты через WinHttpRequest.
Можете поискать - на форуме много где обсуждалось.

13 (изменено: inseption86, 2019-04-03 14:41:04)

Re: AHK: IE COM Multi URL


#NoEnv  ; Recommended for performance and compatibility with future AutoHotkey releases.
SendMode Input  ; Recommended for new scripts due to its superior speed and reliability.
#SingleInstance force 

ie := ComObjCreate("InternetExplorer.Application")
ie.Visible := true
ie.Navigate("https://www.google.com")
ie.Navigate("https://yandex.ru",2048)



w::
 ie := WBFromUrl("https://www.google.com/")
 
 MsgBox % ie.document.getElementsByTagName("input")[1].value
 return
 
q::
 ie2 := WBFromUrl("https://yandex.ru/")
  MsgBox % ie2.document.getElementsByTagName("input")[1].value
 return
 
 
 
 WBFromUrl(url)  {
   shell := ComObjCreate("Shell.Application")
   loop  {
      for window in shell.Windows  {
         if (window.LocationUrl = url)
            break 2
      }
      Sleep 10
   }
   Return window
}

а возможно ли через хром сделать такое?



driver := ComObjCreate("Selenium.ChromeDriver")
driver.AddArgument("--disable-infobars")
driver.AddArgument("--start-maximized") 

driver.Get("https://www.google.com")

driver.ExecuteScript("window.open();")
driver.SwitchToNextWindow
driver.Get("https://yandex.ru")


w::

;"https://www.google.com"

 MsgBox %  driver.findElementsByTag("input").item[2].Attribute("value")
 return
 
q::

; "https://yandex.ru"
   MsgBox % driver.findElementsByTag("input").item[2].Attribute("value")
 return