I´m still crawling in Powershell so decided to ask after trying without being successful.
I have a HTML code like below. I need to extract the Chile word which is present on tr tag and all values present on td tags and export it to a .txt file.
Using the code below it works perfectly BUT it´s depending on the font color:
$result = [regex]::Matches($content, 'style="color:black;".*?>(.*?)</span>')
$result | select { ($_.Groups[1].Value -replace ' ', '' -replace '​', '').Trim().Trim(',')} | Out-file $outfile -Encoding ascii
As you can see on HTML code, some columns (TD) does not have the pattern
How can I get these values in Powershell? I´ve tried below options but no luck:
$result = [regex]::Matches($content, 'style="windowtext;".*?>(.*?)</td>')
$result | select { ($_.Groups[1].Value -replace ' ', '').Trim().Trim(',')} | Out-file $outfile
$result = [regex]::Matches($content, '<td.*?>(.+)</td>')
$result = [regex]::Matches($content, '<td.*?>(.*?)</td>') | % { $_.Captures[0].Groups[1].value} | Out-file $outfile
Again, I need to extract the Chile word which is present on TR tag and all values present on TD tags and export it to a .TXT file.
<tr class="ms-rteFontSize-1 ms-rteTableOddRow-1" dir="rtl" style="height:15pt;"><th class="ms-rteTableFirstCol-1" rowspan="1" colspan="1" style="border- width:medium 1pt 1pt;border-style:none solid solid;padding:0in 5.4pt;width:100px;height:15pt;border-right-color:windowtext;border-bottom- color:windowtext;border-left-color:windowtext;"><div><b><span style="color:black;">Chile</span></b></div></th>
<td width="64" class="ms-rteTableOddCol-1" valign="bottom" style="border-width:medium 1pt 1pt medium;border-style:none solid solid none;padding:0in 5.4pt;width:48pt;height:15pt;border-right-color:windowtext;border-bottom-color:windowtext;">2</td>
<td class="ms-rteTableEvenCol-1" valign="bottom" style="border-width:medium 1pt 1pt medium;border-style:none solid solid none;padding:0in 5.4pt;width:66px;height:15pt;border-right-color:windowtext;border-bottom-color:windowtext;"> </td>
<td class="ms-rteTableOddCol-1" valign="bottom" style="border-width:medium 1pt 1pt medium;border-style:none solid solid none;padding:0in 5.4pt;width:81px;height:15pt;border-right-color:windowtext;border-bottom-color:windowtext;"> </td>
<td width="64" class="ms-rteTableEvenCol-1" valign="bottom" style="border-width:medium 1pt 1pt medium;border-style:none solid solid none;padding:0in 5.4pt;width:48pt;height:15pt;border-right-color:windowtext;border-bottom-color:windowtext;">14,19</td>
<td width="64" class="ms-rteTableOddCol-1" valign="bottom" style="border-width:medium 1pt 1pt medium;border-style:none solid solid none;padding:0in 5.4pt;width:48pt;height:15pt;border-right-color:windowtext;border-bottom-color:windowtext;"><div><span style="color:black;">1</span></div></td>
<td width="64" class="ms-rteTableEvenCol-1" valign="bottom" style="border-width:medium 1pt 1pt medium;border-style:none solid solid none;padding:0in 5.4pt;width:48pt;height:15pt;border-right-color:windowtext;border-bottom-color:windowtext;"><div><span style="color:black;">26</span></div></td>
<td width="64" class="ms-rteTableOddCol-1" valign="bottom" style="border-width:medium 1pt 1pt medium;border-style:none solid solid none;padding:0in 5.4pt;width:48pt;height:15pt;border-right-color:windowtext;border-bottom-color:windowtext;"> </td>
<td width="64" class="ms-rteTableEvenCol-1" valign="bottom" style="border-width:medium 1pt 1pt medium;border-style:none solid solid none;padding:0in 5.4pt;width:48pt;height:15pt;border-right-color:windowtext;border-bottom-color:windowtext;"><div><span style="color:black;">15</span></div></td>
<td class="ms-rteTableOddCol-1" valign="bottom" style="border-width:medium 1pt 1pt medium;border-style:none solid solid none;padding:0in 5.4pt;width:80px;height:15pt;border-right-color:windowtext;border-bottom-color:windowtext;"><div><span style="color:black;">18,19</span></div></td>
<td width="64" class="ms-rteTableEvenCol-1" valign="bottom" style="border-width:medium 1pt 1pt medium;border-style:none solid solid none;padding:0in 5.4pt;width:48pt;height:15pt;border-right-color:windowtext;border-bottom-color:windowtext;"><div><span style="color:black;">9,27</span></div></td>
<td class="ms-rteTableOddCol-1" valign="bottom" style="border-width:medium 1pt 1pt medium;border-style:none solid solid none;padding:0in 5.4pt;width:80px;height:15pt;border-right-color:windowtext;border-bottom-color:windowtext;"><div><span style="color:black;">1</span></div></td>
<td class="ms-rteTableEvenCol-1" valign="bottom" style="border-width:medium 1pt 1pt medium;border-style:none solid solid none;padding:0in 5.4pt;width:80px;height:15pt;border-right-color:windowtext;border-bottom-color:windowtext;"><div><span style="color:black;">8,25</span></div></td></tr>