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

8/22/2022 - Mon
David Johnson, CD

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
Leo Torres

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

Log in or sign up to see answer
Become an EE member today7-DAY FREE TRIAL
Members can start a 7-Day Free trial then enjoy unlimited access to the platform
Sign up - Free for 7 days
Learn why we charge membership fees
We get it - no one likes a content blocker. Take one extra minute and find out why we block content.
See how we're fighting big data
Not exactly the question you had in mind?
Sign up for an EE membership and get your own personalized solution. With an EE membership, you can ask unlimited troubleshooting, research, or opinion questions.
ask a question
Leo Torres


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!
I started with Experts Exchange in 2004 and it's been a mainstay of my professional computing life since. It helped me launch a career as a programmer / Oracle data analyst
William Peck