Powershell Code tune up

This script worked last year
http://www.experts-exchange.com/Programming/Languages/Scripting/Powershell/Q_28223497.html

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/_/year/2012' Site last year
$Website = 'http://espn.go.com/nfl/schedule/_/seasontype/2/week/1' # Site this year
$wc  = New-Object System.Net.WebClient;
$doc = New-Object HtmlAgilityPack.HtmlDocument
$doc.LoadHtml($wc.DownloadString($Website))
 
$games = @()
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 | select -skip 1)
  {
    $col = $row # .Element('td'); 
    if ($col.Attributes["class"].value -eq "colhead")
    { # a day
      $day = $col.ChildNodes[1].InnerText
    } else {  # a game
      $teams = $col.ChildNodes[0].InnerText
      $games += New-Object PsObject -Property @{Week = $Week; Day =$day; Games = $teams}
    }
  }
}

$games | select Week,Day,Games | Format-Table -AutoSize
                                         

Open in new window


The site has changed and now I cant get the code to work and get Game data.

Code should get Week, Day of Game and Game its self.
LVL 8
Leo TorresSQL DeveloperAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

DBAduck - Ben MillerPrincipal ConsultantCommented:
I cannot say what the HTML looked like when it worked, but now it is a mess.  It is not a well formed XHTML so when it goes to select the nodes with table["tablehead"] it comes up with nothing.  Not much you can do to fix their html.
0
Leo TorresSQL DeveloperAuthor Commented:
Yes it was a mess before . What they did this year was now you can select the individual weeks before all the weeks were together.
0
Mihai StancescuSoftware Engineer Commented:
Hi,

For me works ok, I guess.

All I did was to change the reference for html agility from 40 to 20, after downloaded from the link in the script.

Print screen power shell
Regards,
Mishu
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
Leo TorresSQL DeveloperAuthor Commented:
That was to easy.. Wow cant believe I couldn't figure that one out.. Thank you for your help!
0
Leo TorresSQL DeveloperAuthor Commented:
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:\Users\ltorres2\Downloads\PS4\HtmlAgilityPack.1.4.6\Net20\htmlagilitypack.dll
#$Website = 'http://espn.go.com/nfl/schedule/_/year/2012' Site last year
$Website = 'http://espn.go.com/nfl/schedule/_/seasontype/2/week/1' # Site this year
$wc  = New-Object System.Net.WebClient;
$doc = New-Object HtmlAgilityPack.HtmlDocument
$doc.LoadHtml($wc.DownloadString($Website))
 
$games = @()
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 | select -skip 1)
  {
    $col = $row # .Element('td'); 
    if ($col.Attributes["class"].value -eq "colhead")
    { # a day
      $day = $col.ChildNodes[1].InnerText
    } else {  # a game
      $teams = $col.ChildNodes[0].InnerText
      $games += New-Object PsObject -Property @{Week = $Week; Day =$day; Games = $teams}
    }
  }
}

$games | select Week,Day,Games | Format-Table -AutoSize

Open in new window

0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Powershell

From novice to tech pro — start learning today.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.