Read table rows in html Topic is solved

Get help with using AutoHotkey (v1.1 and older) and its commands and hotkeys
glaupomiglio
Posts: 13
Joined: 27 Mar 2017, 20:29

Read table rows in html

28 Mar 2017, 06:23

Hello guys.

How do I go through all the rows of a table in hmtl (the table is dynamic, I do not know how many rows it has) and get the value they contain using autohotkey?

Thank you
User avatar
AlphaBravo
Posts: 586
Joined: 29 Sep 2013, 22:59

Re: Read table rows in html  Topic is solved

28 Mar 2017, 11:01

works for a simple table:

Code: Select all

html =
(
<!DOCTYPE html>
<html>
<head>
</head>
<body>

<table>
  <tr>
    <th>Company</th>
    <th>Contact</th>
    <th>Country</th>
  </tr>
  <tr>
    <td>Alfreds Futterkiste</td>
    <td>Maria Anders</td>
    <td>Germany</td>
  </tr>
  <tr>
    <td>Centro comercial Moctezuma</td>
    <td>Francisco Chang</td>
    <td>Mexico</td>
  </tr>
  <tr>
    <td>Ernst Handel</td>
    <td>Roland Mendel</td>
    <td>Austria</td>
  </tr>
  <tr>
    <td>Island Trading</td>
    <td>Helen Bennett</td>
    <td>UK</td>
  </tr>
  <tr>
    <td>Laughing Bacchus Winecellars</td>
    <td>Yoshi Tannamuri</td>
    <td>Canada</td>
  </tr>
  <tr>
    <td>Magazzini Alimentari Riuniti</td>
    <td>Giovanni Rovelli</td>
    <td>Italy</td>
  </tr>
</table>

</body>
</html>
)


RegExMatch(html, "s)<table>(.*?)</table>", table)										; get table
while pos1 := RegExMatch(table1, "s)<tr>(.*?)</tr>", m, A_Index=1?1:pos1+StrLen(m))				; table rows
{
	while pos2 := RegExMatch(m1, "s)<th>(.*?)</th>", n, A_Index=1?1:pos2+StrLen(n))				; row headers
		res .= n1 "`t"
	res := Trim(res, "`t")
	
	while pos2 := RegExMatch(m1, "s)<td>(.*?)</td>", n, A_Index=1?1:pos2+StrLen(n))				; row columns
		res .= n1 "`t"
	res := Trim(res, "`t")
	res .= "`n"
}
MsgBox % Trim(res, "`n")
glaupomiglio
Posts: 13
Joined: 27 Mar 2017, 20:29

Re: Read table rows in html

29 Mar 2017, 12:15

Hi AlphaBravo, your example worked very well.

Thank you.
Guest

Re: Read table rows in html

30 Mar 2017, 07:30

AlphaBravo, good day.

It's possible retrieve a html from web page? For example :

wb := ComObjCreate("browser here")
wb.Visible := true
wb.Navigate("url here")

SouceCode : = retrieve html from web page here and after using the code your informed in last time.

It's possible ?
User avatar
AlphaBravo
Posts: 586
Joined: 29 Sep 2013, 22:59

Re: Read table rows in html

30 Mar 2017, 10:11

Guest wrote:AlphaBravo, good day.

It's possible retrieve a html from web page? For example :

wb := ComObjCreate("browser here")
wb.Visible := true
wb.Navigate("url here")

SouceCode : = retrieve html from web page here and after using the code your informed in last time.

It's possible ?
there is a couple of ways to do it:

Code: Select all

url := "https://autohotkey.com/boards/viewtopic.php?p=139915#p139915"
WebRequest := ComObjCreate("WinHttp.WinHttpRequest.5.1")
WebRequest.Open("GET", url)
WebRequest.Send()
MsgBox % WebRequest.ResponseText

Code: Select all

MsgBox % IE_DownloadSource("https://autohotkey.com/boards/viewtopic.php?p=139915#p139915")
return

IE_DownloadSource(url, pathToFile="") {
	pwb := ComObjCreate("InternetExplorer.Application"), pwb.Navigate(url)
	While pwb.readyState!=4 || pwb.document.readyState!="complete" || pwb.busy
		Sleep 50
	source := pwb.document.documentElement.outerHTML, pwb.Quit(), pwb := ""
	if pathToFile
	{
		FileAppend, %source%, %pathToFile%
		return True
	}
	else return source
}
glaupomiglio
Posts: 13
Joined: 27 Mar 2017, 20:29

Re: Read table rows in html

31 Mar 2017, 12:50

Very good AlphaBravo.

Thank very much.

Return to “Ask for Help (v1)”

Who is online

Users browsing this forum: doodles333, Google [Bot] and 399 guests