webpages: get table text

Post your working scripts, libraries and tools for AHK v1.1 and older
User avatar
jeeswg
Posts: 6902
Joined: 19 Dec 2016, 01:58
Location: UK

webpages: get table text

29 Oct 2017, 12:49

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
Last edited by jeeswg on 06 Dec 2018, 21:43, edited 3 times in total.
homepage | tutorials | wish list | fun threads | donate
WARNING: copy your posts/messages before hitting Submit as you may lose them due to CAPTCHA
burque505
Posts: 1734
Joined: 22 Jan 2017, 19:37

Re: webpages: get table text

31 Oct 2017, 19:48

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
Last edited by burque505 on 15 Apr 2018, 19:04, edited 1 time in total.
User avatar
jeeswg
Posts: 6902
Joined: 19 Dec 2016, 01:58
Location: UK

Re: webpages: get table text

14 Apr 2018, 23:51

I've updated the script above to handle the new AutoHotkey help which uses IFrames.
homepage | tutorials | wish list | fun threads | donate
WARNING: copy your posts/messages before hitting Submit as you may lose them due to CAPTCHA

Return to “Scripts and Functions (v1)”

Who is online

Users browsing this forum: No registered users and 130 guests