Quantcast
Channel: PowerShell.org » All Posts
Viewing all articles
Browse latest Browse all 13067

Reply To: Downloading Tables from webpages

$
0
0

Here’s a regex solution that works with the posted test data. There appears to be 2 color settings per entry, and none of them have values of Red or Yellow. I’m not sure which one is supposed to change, so I parsed out both of them, and you can key off of whichever one you need.

$data = gc .\Output1.txt -raw

[regex]$regex1 = @’
(?ms)
<TR style=”BACKGROUND-COLOR: \S+?”>
<TD style=”WIDTH: 20%”>.+?</TD>
<TD style=”WIDTH: 20%”>.+?</TD>
<TD style=”BACKGROUND-COLOR: \S+?;.+?</TD>
<TD style=.+?Information>.*?</SPAN></TD></TR>
‘@

$Entries=
($regex1.Matches($data)).groups |
select -ExpandProperty value

[regex]$regex2 = @’
(?ms)
<TR style=”BACKGROUND-COLOR: (\S+?)”>
<TD style=”WIDTH: 20%”>(.+?)</TD>
<TD style=”WIDTH: 20%”>(.+?)</TD>
<TD style=”BACKGROUND-COLOR: (\S+?);.+?</TD>
<TD style=.+?Information>(.*?)</SPAN></TD></TR>
‘@

Foreach ($Entry in $Entries)
{
$Entry -match $regex2 > $null
New-Object PSObject -Property @{
Color = $Matches[1]
Color2 = $Matches[4]
System = $Matches[2]
Message = $Matches[3]
Info = $Matches[5] -replace ‘<BR>’,”`n”
}
}


Viewing all articles
Browse latest Browse all 13067