Skip to content
조회 수 16574 추천 수 0 댓글 0
?

단축키

Prev이전 문서

Next다음 문서

크게 작게 위로 아래로 댓글로 가기 인쇄
?

단축키

Prev이전 문서

Next다음 문서

크게 작게 위로 아래로 댓글로 가기 인쇄

[AHK_L] 현재 열려진 인터넷 창 값 가져오기

 

프레임 제어는 http://www.autohotkey.com/forum/topic70428.html

 

AHK_L(롱) 은 이렇게...

 

#include d:\COM.ahk

IEGet( name="" )
{
   IfEqual, Name,, WinGetTitle, Name, ahk_class IEFrame ; Get active window if no parameter
   Name := ( Name="New Tab - Windows Internet Explorer" ) ? "about:Tabs" : RegExReplace( Name, " - (Windows|Microsoft) Internet Explorer" )
   For pwb in ComObjCreate( "Shell.Application" ).Windows
      If ( pwb.LocationName = Name ) && InStr( pwb.FullName, "iexplore.exe" )
         Return pwb
}

F3::
pwb := IEGet("Access an existing IE object - Microsoft Internet Explorer")
pwb.Visible := True ; Make the IE object visible
Sleep, 2000
test := pwb.document.documentElement.innerText
MsgBox, %test%
return

 

^r::
reload
return

AHK 베이직은 이렇게...

#include d:\COM.ahk
; AHK Basic:

; AHK Basic:

IEGet( name="" )
{
   IfEqual, Name,, WinGetTitle, Name, ahk_class IEFrame ; Get active window if no parameter
   Name := ( Name="New Tab - Windows Internet Explorer" ) ? "about:Tabs" : RegExReplace( Name, " - (Windows|Microsoft) Internet Explorer" )
   oShell := COM_CreateObject( "Shell.Application" ) ; Contains reference to all explorer windows
   Loop, % COM_Invoke( oShell, "Windows.Count" ) {   
      If pwb := COM_Invoke( oShell, "Windows.item[" A_Index-1 "]" )
         If ( COM_Invoke( pwb, "LocationName" ) = name && InStr( COM_Invoke( pwb, "FullName" ), "iexplore.exe" ) )
            Break
      COM_Release( pwb ), pwb := ""
   }
   COM_Release( oShell )
   Return, pwb
}

 

F3::
COM_Init()
pwb := IEGet("Search")
COM_Invoke( pwb, "Visible", True )
Sleep, 2000
;test := pwb.document.DocumentoLottoForm._view_mittente.value
text := COM_Invoke(pwb, "document.documentElement.innerText")

 

MsgBox, %text%

 

Basic Ahk_L COM Tutorial for Webpages

 

 

This guide is not intended to replace the great work that other (more advanced) members have put into other guides. It is designed to help non-coders (n00bz) grasp the basic concepts of AutoHotkey_L COM.

This guide will focus on giving the reader a baseline understanding of the use of the Component Object Model(COM) which can be used to manipulate an application with designed with Document Object Model or DOM such as Internet Explorer.

Q: What is COM? (도대체 컴이 뭐유?)
The Component Object Model is a collection of automation objects that allows a user to interface with various methods and properties of an application.

Q: How do I use it in my script?
There is no easy answer to this question. Why? Because there are different commands to every type of COM object. For instance the methods for Internet Explorer are completely different from MS Office.

In this tutorial I will focus on using COM to script simple commands that will be used to automate IE. Before you can do anything with the IE DOM you have to create a handle to the application.

Code (Copy):
Pwb := ComObjCreate("InternetExplorer.Application")

"Pwb" or Pointer to a Web Browser is the common name for your handle to IE. Your script doesn't care what you name your Pointer you could name it "WhatAboutBob" if you really wanted to.
Now that you have a handle you need to do something with it. Think of it like the steering wheel of a car. Just because you have the wheel in your hands doesn't mean your driving the car.
Code (Copy):
Pwb.Visible := True   

This is the next line of code you will HAVE to have. Your code can work without it but you won't be able to see anything going on. By default IE starts off in invisible mode. I'll go ahead and point out that ".Visible" is NOT AHK code. It is a built in method in the DOM. You can access it through any COM compatible language (Ruby,C++,ect).
Code (Copy):
Pwb.Navigate("Google.com")

At this point we have actually done something. That is open up an instance of IE and navigated to google.com. You could also store an address in a variable.
Code (Copy):
URL = Google.com
Pwb.Navigate(URL)

What about accessing an already open web browser? Good Q! There is no simple command for this. Instead you will have to rely on a function (I did not write) to do this for you.
Code (Copy):
IEGet(Name="")      ;Retrieve pointer to existing IE window/tab
{
   IfEqual, Name,, WinGetTitle, Name, ahk_class IEFrame
      Name := ( Name="New Tab - Windows Internet Explorer" ) ? "about:Tabs"
      : RegExReplace( Name, " - (Windows|Microsoft) Internet Explorer" )
   For Pwb in ComObjCreate( "Shell.Application" ).Windows
      If ( Pwb.LocationName = Name ) && InStr( Pwb.FullName, "iexplore.exe" )
         Return Pwb
} ;written by Jethrow

If your thinking "Holy Heart Attack Batman!" fear not you don't need to understand how this function works to implement it into your script. What this function does is looks through the windows on your computer for IE and then for the tab name of the page you sent it OR default to the last activated tab.
Code (Copy):

Pwb := IEGet()   ;Last active window/tab
;OR
Pwb := IEGet("Google")   ;Tab name you define can also be a variable

Now that we can open IE and navigate to pages we can manipulate things now right? Wrong!

notice the loading bar at the bottom of the page or wherever your browser has it? That is your first adversary. You are going to have to tell your script to wait till your page is done loading.
Code (Copy):

IELoad(Pwb)   ;You must send the function your Handle for it to work

This is a function that is based of the iWeb function Tank built. If you don't care to understand how it works then just know that you must have this (or another similer) function on any script that deals with IE.
Code (Expand - Copy):

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

Now that you can access an existing page or launch a new one we can actually do something useful. Let's fill the search field. We are going to use the "Name" element to do this.
Code (Copy):

Pwb.Document.All.q.Value := "site:autohotkey.com tutorial"

You can also set a form to a variable:
Code (Copy):

Website = site:autohotkey.com tutorial
Pwb.Document.All.q.Value := Website

로그인 후 댓글쓰기가 가능합니다.

?

  1. 14
    Jun 2021
    08:35

    파이썬 Beautifulsoup html의 특정 주소만 가져오기

    Category컴퓨터잡담 Views2967
    Read More
  2. 22
    Feb 2011
    13:00

    클릭해서 새창열리는 페이지에 클릭 또는 값설정 가능한가요?

    CategoryAutoHotKey Views14723
    Read More
  3. 26
    Oct 2013
    15:03

    주문한 부품 리스트

    Category회로도전자부품 Views20733
    Read More
  4. 30
    Mar 2011
    17:18

    정보수집

    CategoryAutoHotKey Views16064
    Read More
  5. 25
    Feb 2012
    12:39

    인터넷 익스플러러 속도 향샹을 위한 팁

    Category컴퓨터잡담 Views24571
    Read More
  6. 17
    Feb 2011
    19:17

    웹페이지의 내용을 변수에 넣기

    CategoryAutoHotKey Views14492
    Read More
  7. 25
    Jan 2018
    13:07

    스프레드시트 autohotkey html gmail 스마트폰 이용하여 핑로스 즉시 알림받기

    Category[Docs]스프레드시트 Views10576
    Read More
  8. 17
    Dec 2011
    17:24

    부팅완료 메시지 프로그램

    CategoryAutoHotKey Views12719
    Read More
  9. 09
    Feb 2011
    19:14

    부팅 완료 체크

    CategoryAutoHotKey Views17864
    Read More
  10. 12
    Feb 2011
    00:31

    [COM] 자바스크립트 / DOM / HTML 웹페이지 컨트롤

    CategoryAutoHotKey Views27281
    Read More
  11. 19
    Dec 2009
    15:15

    [Autohotkey] 인터넷 창을 여러개 띄우고 컨트롤 할때 ahk_id 알아내기

    Category컴퓨터잡담 Views19458
    Read More
  12. 14
    Aug 2010
    23:31

    [autohotkey] 시스템 레지스트리 수정, 삭제

    Category컴퓨터잡담 Views8461
    Read More
  13. 14
    Aug 2010
    23:31

    [autohotkey] 시스템 레지스트리 수정, 삭제

    Category컴퓨터잡담 Views8040
    Read More
  14. 05
    Feb 2011
    08:19

    [autohotkey] FTP-업로드 예제분석

    CategoryAutoHotKey Views18619
    Read More
  15. 04
    Feb 2011
    23:27

    [AUTOHOTKEY] FTP 제어

    CategoryAutoHotKey Views25246
    Read More
  16. 02
    Aug 2011
    16:39

    [AHK_L] 현재 열려진 인터넷 창 값 가져오기

    CategoryAutoHotKey Views16574
    Read More
  17. 16
    Feb 2011
    07:05

    [ahk_l] 섬세한 인터넷 자동검색

    CategoryAutoHotKey Views18182
    Read More
  18. 11
    Feb 2011
    16:55

    [ahk_l] 구글의 Gmail 자동로그인 소스

    CategoryAutoHotKey Views22492
    Read More
  19. 02
    Aug 2011
    17:03

    [AHK_B&AHK_L] 엑셀 제어 비교.

    CategoryAutoHotKey Views20252
    Read More
  20. 08
    Aug 2011
    12:57

    [AHK_B&AHK_L] 익스플로러 HTML 문서정보 알아내기(IE HTML Element Spy)

    CategoryAutoHotKey Views15160
    Read More
Board Pagination Prev 1 2 3 4 5 Next
/ 5

http://urin79.com

우린친구블로그

sketchbook5, 스케치북5

sketchbook5, 스케치북5

나눔글꼴 설치 안내


이 PC에는 나눔글꼴이 설치되어 있지 않습니다.

이 사이트를 나눔글꼴로 보기 위해서는
나눔글꼴을 설치해야 합니다.

설치 취소