Page 1 of 1

webpages: get table text

Posted: 29 Oct 2017, 12:49
by jeeswg

Code: Select all

;example webpages for testing script:
;List of countries and dependencies by population - Wikipedia
;https://en.wikipedia.org/wiki/List_of_countries_and_dependencies_by_population
;Variables and Expressions
;https://autohotkey.com/docs/Variables.htm#BuiltIn

;[WBGet function]
;WBGet function - AutoHotkey Community
;https://autohotkey.com/boards/viewtopic.php?f=6&t=39869

q:: ;html tables - get text
WinGet, hWnd, ID, A
oWB := WBGet("ahk_id " hWnd)

;if AutoHotkey help, get IFrame
;MsgBox, % oWB.document.parentWindow.frames.length
if InStr(oWB.document.url, "://autohotkey.com/docs")
{
	vNum := 0
	;IID_IHTMLWindow2 := "{332C4427-26CB-11D0-B483-00C04FD90119}"
	oWB := ComObject(9, ComObjQuery(oWB.document.parentWindow.frames[vNum], "{332C4427-26CB-11D0-B483-00C04FD90119}", "{332C4427-26CB-11D0-B483-00C04FD90119}"), 1)
}

;MsgBox, % oWB.document.all.length
oTables := oWB.document.getElementsByTagName("table")
Loop, % oTables.length
{
	oTable := oTables[A_Index-1]
	oRows := oTable.rows
	vOutput := ""
	Loop, % oRows.length
	{
		vOutput .= (A_Index=1?"":"`r`n")
		oCells := oRows[A_Index-1].cells
		Loop, % oCells.length
			vOutput .= (A_Index=1?"":"`t") oCells[A_Index-1].innerText
	}
	;Clipboard := vOutput "`r`n"
	MsgBox, % vOutput
}
oWB := oTables := oTable := oRows := oCells := ""
MsgBox, % "done"
return
Links:
Internet Explorer get element under cursor (show borders, show text) (any zoom percentage) - AutoHotkey Community
https://autohotkey.com/boards/viewtopic.php?f=6&t=29458
Simple HTML Table Parse - AutoHotkey Community
https://autohotkey.com/boards/viewtopic ... 68#p178768
webpages: get icon urls - AutoHotkey Community
https://autohotkey.com/boards/viewtopic.php?f=5&t=38936

Re: webpages: get table text

Posted: 31 Oct 2017, 19:48
by burque505
Pretty nice, jeeswg. Here's your code with the WBGet function pasted in at the bottom, in case that link disappears :)
Also Alt-Escape bails out.
Spoiler
Regards,
burque505

Re: webpages: get table text

Posted: 14 Apr 2018, 23:51
by jeeswg
I've updated the script above to handle the new AutoHotkey help which uses IFrames.