[PA] 업무자동화/[AH]Autohotkey

AH HTML 통으로 읽기,요소 읽어내기

Weneedu 2020. 6. 21. 13:09

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