Powershell select leaf nodes

I believe I in the right top node. I how do I traverse down to the node I need. Code is attached and a Screen shot of Node I am on and node I want to get to. I want to return the "UTA" for away team.

Add-Type -path C:\pstemp\HtmlAgilityPack\Net40\htmlagilitypack.dll

CLS

$Website = "http://www.nba.com/gameline/20151031/"
$wc = New-Object System.Net.WebClient;
$doc = New-Object HtmlAgilityPack.HtmlDocument
$doc.LoadHtml($wc.DownloadString($Website))

$games = @()
$Allgames = @()

foreach ($node1 in $doc.DocumentNode.SelectNodes("//div[@class='nbaModOuterBox gameModule']"))
{

	foreach ($node2 in $node1.DocumentNode.SelectNodes("//div[@class='nbaModTopTeamAw']") )
	{
		$AwayTeam = $node2.Innertext
		Write-Host $AwayTeam
	}
	
}

Open in new window


Sample
LVL 8
Leo TorresSQL DeveloperAsked:
Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

x
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.

Leo TorresSQL DeveloperAuthor Commented:
Made some progress this way but I can seem to get the first 4 records to parse correctly only the last 2

CLS

# HAP available at http://htmlagilitypack.codeplex.com/
# (originally http://www.nuget.org/packages/HtmlAgilityPack)
Add-Type -path C:\pstemp\HtmlAgilityPack\Net40\htmlagilitypack.dll

$Website = "http://www.nba.com/gameline/20151031/"
$wc = New-Object System.Net.WebClient;
$doc = New-Object HtmlAgilityPack.HtmlDocument
$doc.LoadHtml($wc.DownloadString($Website))

$games = @()
$Allgames = @()
foreach ($day in $doc.DocumentNode.SelectNodes("//div[@class='nbaModOuterBox gameModule']"))
{
	$rows = $day.SelectNodes('div')
	$lines = $rows[0].InnerText.split('`n')# | where { $rows[0].InnerText[0] -like ' '  }
        
        $gameTime = $lines[0].substring(0, 7)
	$AwayTeam = $lines[1..2].substring(2, 3)
	$HomeTeam = $lines[1..2].substring(5, 3)

	Write-Host $gametime " " $AwayTeam " " $HomeTeam


}

Open in new window

Rainer JeschorCommented:
Hi,
could you please explain in words, which parts of the page you want to capture?

As far as I can see, the gametime is only available on the current day, not in the past.

Thanks.
Rainer
Leo TorresSQL DeveloperAuthor Commented:
Hello Rainer correct. just replace the "/20151031/" at the end of the link to a future date

I need the gametime value and the to teams playing at that time
Determine the Perfect Price for Your IT Services

Do you wonder if your IT business is truly profitable or if you should raise your prices? Learn how to calculate your overhead burden with our free interactive tool and use it to determine the right price for your IT services. Download your free eBook now!

Qlemo"Batchelor", Developer and EE Topic AdvisorCommented:
I'm not clear about the intended output. Can you show a future game result as you expect it to be?
Leo TorresSQL DeveloperAuthor Commented:
sorry for the delayed response. I need the gametime, and each team. That's  it 3 itmes.
Leo TorresSQL DeveloperAuthor Commented:
Sample
Gametime                 AwayTeam                Hometeam
     7:30PM                       MIA                             ORL

This is an example this data may not exists I just created off the top of my head. If you want to test the webpage you have to choose a future date in the link. Games in the past do not have a Gametime value.
Qlemo"Batchelor", Developer and EE Topic AdvisorCommented:
Only using XPath it looks much better:
CLS

# HAP available at http://htmlagilitypack.codeplex.com/
# (originally http://www.nuget.org/packages/HtmlAgilityPack)
Add-Type -path C:\pstemp\HtmlAgilityPack\Net40\htmlagilitypack.dll

$Website = "http://www.nba.com/gameline/20151115/"
$wc = New-Object System.Net.WebClient;
$doc = New-Object HtmlAgilityPack.HtmlDocument
$doc.LoadHtml($wc.DownloadString($Website))

$games = @()
$Allgames = @()
foreach ($day in $doc.DocumentNode.SelectNodes("//div[@class='nbaOuterBox']"))
{
  $gameTime = $day.SelectSingleNode("..//p[@class='nbaPreStatTx']").InnerText.Substring(0,7)
  $AwayTeam = $day.SelectSingleNode("..//h5[@class='nbaModTopTeamName awayteam']").InnerText
  $HomeTeam = $day.SelectSingleNode("..//h5[@class='nbaModTopTeamName hometeam']").InnerText

  Write-Host "$gametime $AwayTeam $HomeTeam"
}

Open in new window

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:
Thank You!
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.