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
Read table rows in html Topic is solved
-
- Posts: 13
- Joined: 27 Mar 2017, 20:29
- AlphaBravo
- Posts: 586
- Joined: 29 Sep 2013, 22:59
Re: Read table rows in html Topic is solved
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")
-
- Posts: 13
- Joined: 27 Mar 2017, 20:29
Re: Read table rows in html
Hi AlphaBravo, your example worked very well.
Thank you.
Thank you.
Re: Read table rows in html
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 ?
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 ?
- AlphaBravo
- Posts: 586
- Joined: 29 Sep 2013, 22:59
Re: Read table rows in html
there is a couple of ways to do it: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 ?
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
}
-
- Posts: 13
- Joined: 27 Mar 2017, 20:29
Re: Read table rows in html
Very good AlphaBravo.
Thank very much.
Thank very much.
Who is online
Users browsing this forum: just me and 315 guests