troubleshooting Question

Powershell, Split String

Avatar of Leo Torres
Leo TorresFlag for United States of America asked on
.NET ProgrammingC#Powershell
4 Comments1 Solution732 ViewsLast Modified:
Code is close but no cigar.

Day and games data in the same column Day should be repeated for each game on that date.

$Week Variable is there a way to just grab data from node? I dont wan to use a replace in case that value changes.

<#
.SYNOPSIS
   <A brief description of the script>
.DESCRIPTION
   <A detailed description of the script>
.PARAMETER <paramName>
   <Description of script parameter>
.EXAMPLE
   <An example of using the script>
#>

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'
$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'); 
   $time  = $col.InnerText
  #  $col = $col.NextSibling; 
 	$teams = $col.InnerText[2] #| Select -ExpandProperty InnerText) #-join " at "
    $games += New-Object PsObject -Property @{Week = $Week; Day = $time; Teams = $teams}
  }
}

$Allgames += $games

$Allgames | select Week,Day,@{Name='Games';Expression={[string]$_.Teams}} | Format-Table -AutoSize
Join the community to see this answer!
Join our exclusive community to see this answer & millions of others.
Unlock 1 Answer and 4 Comments.
Join the Community
Learn from the best

Network and collaborate with thousands of CTOs, CISOs, and IT Pros rooting for you and your success.

Andrew Hancock - VMware vExpert
See if this solution works for you by signing up for a 7 day free trial.
Unlock 1 Answer and 4 Comments.
Try for 7 days

”The time we save is the biggest benefit of E-E to our team. What could take multiple guys 2 hours or more each to find is accessed in around 15 minutes on Experts Exchange.

-Mike Kapnisakis, Warner Bros