I am trying to pull an HTML table from a webpage using PowerShell, but I'm having trouble calling the table itself. There are two tables on the page, one for input and another for output, and ideally I would like to check if the output table contains anything (apart from a specific string to indicate no results), and if it does put the information from said table into a file.
I've tried using Invoke-Webrequest
's ParsedHtml
property, but the tables don't have specific element names or ID's, nor do they have 'class' or 'title' tags to differentiate the two. Using the .IHTMLDocument2_all
property did show several COMObjects (in the format TypeName: System.__ComObject#{3050f539-98b5-11cf-bb82-00aa00bdce0b}
) that I feel I need to somehow call in order to get what I need, but I can't figure out how to do so.
Is there a way to call those COMObjects, so I can pull the information from inside of them?
Here is the HTML for the table I am trying to pull results from (when there are no results):
<Center>
<TABLE CELLSPACING=0 CELLPADDING=0 BORDER=2><TR><TD>
<TABLE CELLSPACING=0 CELLPADDING=2 BORDER=0>
<TR><TD BGCOLOR=3399FF ALIGN=CENTER><NOBR><FONT FACE="Arial" SIZE=+1><B> Search Results </B></FONT></NOBR></TD></TR>
<TR><TD><TABLE WIDTH=100% CELLSPACING=0 CELLPADDING=2 BORDER=0>
<Center>
<table width="100%" cellpadding="5" cellspacing="0">
<tr>
<td>No assets were found for the search</td>
</tr>
</TABLE></TD></TR>
</TABLE></TD></TR>
</TABLE>
</Center>
When there are results, there are several headers under which the results are displayed, in this code:
<Center>
<TABLE CELLSPACING=0 CELLPADDING=0 BORDER=2><TR><TD>
<TABLE CELLSPACING=0 CELLPADDING=2 BORDER=0>
<TR><TD BGCOLOR=3399FF ALIGN=CENTER><NOBR><FONT FACE="Arial" SIZE=+1><B> Search Results </B></FONT></NOBR></TD></TR>
<TR><TD><TABLE WIDTH=100% CELLSPACING=0 CELLPADDING=2 BORDER=0>
<Center>
<table width="100%" cellpadding="5" cellspacing="0">
<tr bgcolor=A9A9A9>
<th>HEADER1</th>
<th>HEADER2</th>
<th>HEADER3</th>
<th>HEADER4</th>
<th>HEADER5</th>
<th>HEADER6</th>
<th>HEADER7</th>
<th>HEADER8</th>
<th>HEADER9</th>
<th>HEADER10</th>
<th>HEADER11</th>
<th>HEADER12</th>
<th>HEADER13</th>
</tr>
<tr >
<td nowrap><font size= "-1" color=000000>**RESULTS**</td>
<td nowrap><font size= "-1" color=000000>**RESULTS**</td>
<td nowrap><font size= "-1" color=000000>**RESULTS</td>
<td nowrap><font size= "-1" color=000000>**RESULTS**</td>
<td nowrap><font size= "-1" color=000000>**RESULTS**</td>
<td nowrap><font size= "-1" color=000000>**RESULTS**</td>
<td nowrap><font size= "-1" color=000000>**RESULTS**</td>
<td nowrap><font size= "-1" color=000000>**RESULTS**</td>
<td nowrap><font size= "-1" color=000000>**RESULTS**</td>
<td nowrap><font size= "-1" color=000000>**RESULTS**</td>
<td nowrap><font size= "-1" color=000000> </td>
<td nowrap><font size= "-1" color=000000>**RESULTS**</td>
<td nowrap><font size= "-1" color=000000> </td>
<tr>
<tr bgcolor=C0C0C0>
<td nowrap><font size= "-1" color=000000>**RESULTS**</td>
<td nowrap><font size= "-1" color=000000>**RESULTS**</td>
<td nowrap><font size= "-1" color=000000>**RESULTS**</td>
<td nowrap><font size= "-1" color=000000>**RESULTS**</td>
<td nowrap><font size= "-1" color=000000>**RESULTS**</td>
<td nowrap><font size= "-1" color=000000>**RESULTS**</td>
<td nowrap><font size= "-1" color=000000>**RESULTS**</td>
<td nowrap><font size= "-1" color=000000>**RESULTS**</td>
<td nowrap><font size= "-1" color=000000>**RESULTS**</td>
<td nowrap><font size= "-1" color=000000>**RESULTS**</td>
<td nowrap><font size= "-1" color=000000> </td>
<td nowrap><font size= "-1" color=000000>**RESULTS**</td>
<td nowrap><font size= "-1" color=000000> </td>
<tr>
<tr >
<td nowrap><font size= "-1" color=000000>**RESULTS**</td>
<td nowrap><font size= "-1" color=000000>**RESULTS**</td>
<td nowrap><font size= "-1" color=000000>**RESULTS**</td>
<td nowrap><font size= "-1" color=000000>**RESULTS**</td>
<td nowrap><font size= "-1" color=000000>**RESULTS**</td>
<td nowrap><font size= "-1" color=000000>**RESULTS**</td>
<td nowrap><font size= "-1" color=000000>**RESULTS**</td>
<td nowrap><font size= "-1" color=000000>**RESULTS**</td>
<td nowrap><font size= "-1" color=000000>**RESULTS**</td>
<td nowrap><font size= "-1" color=000000>**RESULTS**</td>
<td nowrap><font size= "-1" color=000000> </td>
<td nowrap><font size= "-1" color=000000>**RESULTS**</td>
<td nowrap><font size= "-1" color=000000> </td>
<tr>
</TABLE></TD></TR>
</TABLE></TD></TR>
</TABLE>
</Center>
Ideally, I would like to check if assets were found, and if they were, pull the results from under headers 1, 2, 3, 6, and 7 into a usable form (most likely a table or a .csv file). Any help is greatly appreciated.