Link to home
Start Free TrialLog in
Avatar of Leo Torres
Leo TorresFlag for United States of America

asked on

Powershell, Split String

Again I cant seem to align my columns here games are fine but time and date are skewed. What is my issue this same as last time but I cant seem to put a finger on it.

My games has Dates and My date column just has a constant. when it should be a date.

CLS

# HAP available at http://htmlagilitypack.codeplex.com/
# (originally http://www.nuget.org/packages/HtmlAgilityPack)
Add-Type -path C:\pstemp\HtmlAgilityPack\Net40\htmlagilitypack.dll
#Add-Type -path C:\pstemp\HtmlAgilityPack\Net20\htmlagilitypack.dll
$Website = 'http://espn.go.com/nfl/schedule'
$wc  = New-Object System.Net.WebClient;
$doc = New-Object HtmlAgilityPack.HtmlDocument
$doc.LoadHtml($wc.DownloadString($Website))
 
$games = @()
$Allgames = @()
foreach ($day in $doc.DocumentNode.SelectNodes('//table["tablehead"]'))
{
  $rows = $day.SelectNodes('tr')
  $Week = $rows[0].InnerText -replace "back to top &#187;", ""<# [DateTime] #>

  foreach ($row in $rows[2..$rows.Count])
  {
    $col = $row.Element('td'); 
        if ($col.Attributes["class"].value -eq "colhead")
            { # a day
                    $day = $col.ChildNodes[1].InnerText
            } 

    $teams  = $col.InnerText
    $col = $col.NextSibling; 
    $time = ($col.ChildNodes[0,2] | Select -ExpandProperty InnerText) -join " at "
    $games += New-Object PsObject -Property @{Week = $week;date = $day; time = $time; Teams = $teams}
  }
}

$Allgames += $games

$Allgames | select Week,Date,time,@{Name='Games';Expression={[string]$_.Teams}} | Format-Table -AutoSize

Open in new window

ASKER CERTIFIED SOLUTION
Avatar of Qlemo
Qlemo
Flag of Germany image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of Leo Torres

ASKER

Dont want to be much of a bother this is going to a table any way I can delete rows there.

I tried to put the time outside of loop. An failed again. but thank I need this before the 5th. Once the first game happens the page changes...

Thanks again!
Thanks for being patient!