Avatar of Leo Torres
Leo TorresFlag for United States of America

asked on 

Powershell, Split String

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.

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

# 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
$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

Open in new window

Powershell.NET ProgrammingC#

Avatar of undefined
Last Comment
Leo Torres
Avatar of David Johnson, CD
David Johnson, CD
Flag of Canada image

Your error is further up in the code
$Allgames += $games
$Allgames | select Week,Day | fl
gives the output of:
Week : Week 17
Day  : Denver 38, Kansas City 3
Week : Week 17
Day  : Washington 28, Dallas 18
Avatar of Leo Torres
Leo Torres
Flag of United States of America image


So what is your suggested change.
This line is at the bottom "$Allgames += $games"

The error has to be above this line? What are you suggesting
Avatar of Qlemo
Flag of Germany image

Blurred text
View this solution by signing up for a free trial.
Members can start a 7-Day free trial and enjoy unlimited access to the platform.
See Pricing Options
Start Free Trial
Avatar of Leo Torres
Leo Torres
Flag of United States of America image



Thank you this works I need some time to analyze and consume information. I know this one is a bit different but I tried to tackle it based on what I learned from you to see if I could apply new knowledge (I was unsuccessful that's why I put up the question). Some info back just not in the right columns.

Once I review I will open a new question with questions about code so can explain for credit.

Thanks again!
.NET Programming
.NET Programming

The .NET Framework is not specific to any one programming language; rather, it includes a library of functions that allows developers to rapidly build applications. Several supported languages include C#, VB.NET, C++ or ASP.NET.

Top Experts
Get a personalized solution from industry experts
Ask the experts
Read over 600 more reviews


IBM logoIntel logoMicrosoft logoUbisoft logoSAP logo
Qualcomm logoCitrix Systems logoWorkday logoErnst & Young logo
High performer badgeUsers love us badge
LinkedIn logoFacebook logoX logoInstagram logoTikTok logoYouTube logo