Skip to content
AutoHotKey
2011.02.16 07:05

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

조회 수 18182 추천 수 0 댓글 0
?

단축키

Prev이전 문서

Next다음 문서

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

단축키

Prev이전 문서

Next다음 문서

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

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

;AHK_L에서는 제대로 입력이 되네요. 

;(AHK_L Unicode Build v1.0.92.02 + Win 7 SP1 + IE 9 RC) 



ie := ComObjCreate("InternetExplorer.Application") 

ie.Visible := True 

ie.Navigate("http://www.google.co.kr/") 

While ie.Busy() 

    Sleep, 50 

MsgBox, 로드 완료`n`n폼에 문자를 입력합니다. 

form := ie.document.GetElementsByTagName("FORM")[0] 

form.q.value := "0987654321" 

MsgBox, 폼 송신 완료 

form.submit() 

While ie.Busy() 

    Sleep, 50 

MsgBox, 검색결과가 표시되었습니다.`n`n종료합니다. 

form:="" 

ie.Quit() ; 종료시키지 않으면 iexplore.exe 프로세스가 남으므로 주의 

return





참고주소 및 소스 : http://www.autohotkey.com/forum/topic51020.html


In the image above, note the document object - you will be using this object quite often. To access the Webpage, you will need to navigate through the HTML DOM. Here are some simple ways to do this:

  • Object Name & Index 
    Say you want to get the value of the 1st element in the 1st form, which will be the Search for Keywords Input Box. The path would look like this (a collection of objects starts at 0):
    Code:
    document.forms[0].elements[0].value
    Now if you want to show the value of the element in a pop-up, simply put this javascript in your URL Address bar and hit enter:
    Code:
    javascript: alert(document.forms[0].elements[0].value)
    MsgBox % pwb.document.forms[0].elements[0].value
    MsgBox % COM_Invoke(pwb, "document.forms[0].elements[0].value")

  • Object's Name / ID Attribute 
    You can also use the objects name or ID. For example, the 1st forms name is SearchForm, with its 1st elements name being search_keywords. The following javascript fed throught the address bar would produce the same results:
    Code:
    javascript: alert(document.SearchForm.search_keywords.value)
    MsgBox % pwb.document.SearchForm.search_keywords.value
    MsgBox % COM_Invoke(pwb, "document.SearchForm.search_keywords.value")
    Or if you only know the elements name is search_keywords, you could display the value of that element using all, which references all the elements on the webpage:
    Code:
    javascript: alert(document.all.search_keywords.value)
    MsgBox % pwb.document.all.search_keywords.value
    MsgBox % COM_Invoke(pwb, "document.all.search_keywords.value")

  • getElement Methods 
    If you want to get an element(s) based on limited criteria, you can use the following 3 methods:
    • getElementById(id) - returns a reference to the first object with the specified ID 
    • getElementsByName(name) - Returns a collection of objects with the specified name 
    • getElementsByTagName(tagname) - Returns a collection of objects with the specified tagname
    The following example will display the value of the Search for Author Input Box, which is the 4th element on the webpage with an INPUT Tag: 
    (Note - the item number may be dynamic)
    Code:
    javascript: alert(document.getElementsByTagName('input')[3].value)
    MsgBox % pwb.document.getElementsByTagName("input")[3].value
    MsgBox % COM_Invoke(pwb, "document.getElementsByTagName[input].item[3].value")

Controlling the WebPage 
So far we have just retrieved information from the webpage. Now lets start controlling the webpage. Note - if the JavaScript doesn't end with a Method, use void 0.
  • Focus on a Webpage Element - focus() 
    Sets the focus to the Search for Keywords Input Box:
    Code:
    javascript: document.all.search_keywords.focus()
    pwb.document.all.search_keywords.focus()
    COM_Invoke(pwb, "document.all.search_keywords.focus")

  • Click on a Webpage Element - click() 
    Clicks the Search button:
    Code:
    javascript: document.getElementsByTagName('input')[11].click()
    pwb.document.getElementsByTagName("input")[11].click()
    COM_Invoke(pwb, "document.getElementsByTagName[input].item[11].click")

  • Set Value of an Input Field - value 
    Sets the value of the Search for Keywords Input Box:
    Code:
    javascript: document.all.search_keywords.value = 'Input Value'; void 0
    pwb.document.all.search_keywords.value := "Input Value"
    COM_Invoke(pwb, "document.all.search_keywords.value", "Input Value")

  • Dropdown Box Selection - selectedIndex
    Quote:
    <SELECT class=post name=sort_by><OPTION selected value=0>Post Time</OPTION><OPTION value=1>Post Subject</OPTION><OPTIONvalue=2>Topic Title</OPTION><OPTION value=3>Author</OPTION><OPTION value=4>Forum</OPTION></SELECT>
    This is the HTML for the Sort By Dropdown. The following will set the Dropdown to Author:
    Code:
    javascript: document.all.sort_by.selectedIndex = 3; void 0   ; Note - you could use value = 3
    pwb.document.all.sort_by.selectedIndex := 3
    COM_Invoke(pwb, "document.all.sort_by.selectedIndex", 3)

  • Radio / Checkbox Selection - checked
    Quote:
    <INPUT value=ASC type=radio name=sort_dirAscending<BR><INPUT value=DESC CHECKED type=radio name=sort_dirDescending
    This is the HTML for the Sort By Radio selection. The following will set the Radio to Ascending:
    Code:
    javascript: document.all.sort_dir[0].checked = true; void 0
    pwb.document.all.sort_dir[0].checked := True
    COM_Invoke(pwb, "document.all.sort_dir[0].checked", True)

  • Get Text from a WebPage Element - innerText 
    Say you want to get the text at the top of the page (innerHTML will give you all the HTML):
    Code:
    text := pwb.document.getElementsByTagName("TD")[2].innerText
    text := COM_Invoke(pwb, "document.getElementsByTagName[TD].item[2].innerText")
    ... or if you want all the text (or html) from the page:
    Code:
    text := pwb.document.documentElement.innerText
    text := COM_Invoke(pwb, "document.documentElement.innerText")

There you have it! These techniques should help get you started. Next, I would recommend the following:
  1. Try these Controls out on some of your favorite webpages.
  2. Find some more JavaScript examples, and then try "translating" them to COM. (JavaScript is well documented online)
  3. Learn additional ways to access the HTML DOM.
You may be wondering, "How do I find information about the element so I can access it?" Good question! The following tools can help you with that. 

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

?

List of Articles
번호 분류 제목 날짜 조회 수
27 AutoHotKey UrlDownloadToVar() 1 2011.02.09 15464
26 AutoHotKey WinMenuSelectItem로 메뉴선택하기 1 2011.02.17 16252
25 컴퓨터잡담 [AHK] AutoHotkey_N, AutoHotkey.dll 1 2011.07.28 13562
24 컴퓨터잡담 [AHK] COM Standard Library 1 1 2011.07.28 13588
23 AutoHotKey [ahk] 다른 프로그램의 트레이 아이콘을 숨기기 1 4 2011.02.16 19005
22 AutoHotKey [ahk] 레지스터리 등록여부 확인 후 없으면 추가시키기 2 1 2011.02.14 14972
21 AutoHotKey [ahk]웹페이지가 띄워진 창 내용을 추출하여 로딩이 완료되었는지를 확인할 수 있는 소스 2011.02.25 14747
20 AutoHotKey [AHK_B&AHK_L] 익스플로러 HTML 문서정보 알아내기(IE HTML Element Spy) 2011.08.08 15160
19 AutoHotKey [AHK_B&AHK_L] 엑셀 제어 비교. 2 2011.08.02 20252
18 AutoHotKey [ahk_l] 구글의 Gmail 자동로그인 소스 3 2011.02.11 22492
» AutoHotKey [ahk_l] 섬세한 인터넷 자동검색 2011.02.16 18182
16 AutoHotKey [AHK_L] 현재 열려진 인터넷 창 값 가져오기 4 2011.08.02 16574
15 AutoHotKey [AUTOHOTKEY] FTP 제어 file 2011.02.04 25246
14 AutoHotKey [autohotkey] FTP-업로드 예제분석 2 file 2011.02.05 18619
13 컴퓨터잡담 [autohotkey] 시스템 레지스트리 수정, 삭제 2010.08.14 8461
12 컴퓨터잡담 [autohotkey] 시스템 레지스트리 수정, 삭제 1 3 2010.08.14 8040
11 컴퓨터잡담 [Autohotkey] 인터넷 창을 여러개 띄우고 컨트롤 할때 ahk_id 알아내기 1 3 2009.12.19 19458
10 AutoHotKey [COM] 자바스크립트 / DOM / HTML 웹페이지 컨트롤 3 2011.02.12 27281
9 AutoHotKey 부팅 완료 체크 2011.02.09 17864
8 AutoHotKey 부팅완료 메시지 프로그램 file 2011.12.17 12719
Board Pagination Prev 1 2 3 4 5 Next
/ 5

http://urin79.com

우린친구블로그

sketchbook5, 스케치북5

sketchbook5, 스케치북5

나눔글꼴 설치 안내


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

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

설치 취소