Home PowerShell - filter output datas from html table
Reply: 0

PowerShell - filter output datas from html table

Munteanu Doru
Munteanu Doru Published in 2017-09-14 10:28:28Z

I managed to get entire table from a page with the following code, but I want to ask you if you can help me to filter values from 4th column and if value is > 20 to get as output all entire row of specific value (rest will be ignored). Thank you. Is more for learning, but this kind of script is very useful for people that are working with table extraction.

$r = Invoke-WebRequest https://en.wikipedia.org/wiki/Divorce_demography
$data = ( $r.ParsedHtml.getElementsByTagName("table") | Select-Object -First 1 ).rows
$table = @()
forEach($datum in $data){
    if($datum.tagName -eq "tr"){
        $thisRow = @()
        $cells = $datum.children
        forEach($cell in $cells){
            if($cell.tagName -imatch "t[dh]"){
                $thisRow += $cell.innerText
        $table += $thisRow -join ","
$table | out-file E:\test.csv -Encoding ascii

this code could be added to script ?

 if ($html.table.tr[$i].td[3] -eq 0) {}
You need to login account before you can post.

About| Privacy statement| Terms of Service| Advertising| Contact us| Help| Sitemap|
Processed in 0.330383 second(s) , Gzip On .

© 2016 Powered by cudou.com design MATCHINFO