20200621 1302 

 

 

20200601 0906 AH HTML 읽기

01 URL찾기 하나의 웹으로 보이지만, 여러 개의 frame으로 나뉘어 있고, 그 frame안에 주소도 미리 정해진 것(static)이 아니라, 사용자 요구에 따라 변하기(dynamic)때문에 URL찾기가 쉽지 않다. 결국은 HTML source을 읽고 찾아내야한다.

 

02 HTML 통으로 읽기

web:=ComObjCreate("WinHttp.WinHttpRequest.5.1")

zURL .=zNmb

web.open("GET",zURL)

web.send()

zTmp:=web.responseText

;uncomment comments

zTmp:=strreplace(zTmp,"<!--<td>","<td>") ;uncomment

zTmp:=strreplace(zTmp,"</td>-->","</td>") ;uncomment

;body만 읽어내기

zDocu:=ComObjCreate("HTMLfile")

zDocu.write(zTmp)

zLen:=zDocu.getElementsByclassName("content_lst content_lst_body").length;요소별 읽기 x:=zDocu.getElementsByclassName("content_lst content_lst_body")[0].innerText

 

03 HTML 요소 읽어내기 as parsing

zURL .=”http://test.html”

web:=ComObjCreate("InternetExplorer.Application")

web.navigate(zURL)

web.visible := true

zTables:=web.document.getElementsByTagName("table")

zOutMerge:=""

loop % zTables.length ;loop 1

{

zTable:=zTables[A_Index-1]

zRows:=zTable.rows

zOut:=""

loop,% zRows.length

{

zOut .=(A_Index=1?"":"`r`n")

zCells:=zRows[A_Index-1].cells

loop,% zCells.length

zOut .=(A_Index=1?"":"`t") zCells[A_Index-1].innerText

}

zOutMerge:= zOutMerge "[" A_Index "]" "`n" zOut " `r `n"

;MsgBox,% zOutMerge

}

FileAppend, %zOutMerge%, zOut.txt

ExitApp

^ESC::ExitApp

'[PA] 업무자동화 > [AH]Autohotkey' 카테고리의 다른 글

AH OCR API 사용하기  (0) 2020.06.27
AH IE 새 탭에서 열기  (0) 2020.06.26
AH 이미지 크기 알아내기  (0) 2020.06.21
AH 윈도우 요소, HTML 요소 알아내기  (0) 2020.06.21
AH HTML 다루기 3  (0) 2020.06.06
Posted by Weneedu
,


출처: https://privatedevelopnote.tistory.com/81 [개인노트]