Advertisement
upz

SuperLigaData Eksempel

upz
Oct 23rd, 2017
342
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. $website = Invoke-WebRequest -Uri 'https://www.bold.dk/fodbold/danmark/superligaen/'
  2.  
  3. ##################
  4. # Match OverView #
  5. ##################
  6.  
  7. $teams = ($website.AllElements | where {$_.class -match 'team_name_container'}).innertext | select -Unique
  8. $games_played = (($website.AllElements | where {$_.class -match 'played kvut'}) | where {$_.total -ne ''}).total
  9. $games_won = (($website.AllElements | where {$_.class -match 'wins kvut'}) | where {$_.total -ne ''}).total
  10. $games_draw = (($website.AllElements | where {$_.class -match 'draws kvut'}) | where {$_.total -ne ''}).total
  11. $games_lost = (($website.AllElements | where {$_.class -match 'defeits kvut'}) | where {$_.total -ne ''}).total
  12. $goals = (($website.AllElements | where {$_.class -match 'goals'}) | where {$_.total -ne $null}).total -replace (' ','')
  13. $points = (($website.AllElements | where {$_.class -match 'points'}) | where {$_.total -ne $null -and $_.total -ne ''}).total
  14.  
  15. $game_stats = New-Object -TypeName System.Collections.Generic.List[PsObject]
  16.  
  17. for ($i = 0; $i -lt $teams.count;$i++)
  18. {
  19.     $properties = [ordered]@{
  20.         'Team' = $teams[$i]
  21.         'Games_Played' = $games_played[$i]
  22.         'Games_Won' = $games_won[$i]
  23.         'Games_Draw' = $games_draw[$i]
  24.         'Games_Lost' = $games_lost[$i]
  25.         'Goals' = $goals[$i]
  26.         'Points' = $Points[$i]
  27.     }
  28.  
  29.     $obj = New-Object -TypeName psobject -Property $properties
  30.     $game_stats.Add($obj)
  31. }
  32.  
  33. ##########
  34. # Match #
  35. ##########
  36.  
  37. $dato = (($website.AllElements | where {$_.class -eq 'start small'} ).innerhtml)
  38. $tid = (((($website.AllElements | where {$_.class -eq 'time'} ).innerhtml)) -replace("tid","") | where {$_})
  39. $kampe = (((($website.AllElements | where {$_.class -eq 'name'} ).innerhtml)) -replace("kampe","") | where {$_})
  40. $scores = ((($website.AllElements | where {$_.class -eq 'score'} ).innerhtml))
  41.  
  42. $Match_stats = New-Object -TypeName System.Collections.Generic.List[PsObject]
  43.  
  44. for ($i=0;$i -lt $dato.count;$i++)
  45. {
  46.     $properties = [ordered]@{
  47.         'Dato' = (($dato[$i] -split("/`">","")[0] -replace("&nbsp;"," "))[-1] -split("</a>"))[0]
  48.         'Tid' = (($tid[$i] -split("/`">","")[0] -replace("&nbsp;"," "))[-1] -split("</a>"))[0]
  49.         'Kamp' = (($kampe[$i] -split("/`">","")[0] -replace("&nbsp;"," "))[-1] -split("</a>"))[0]
  50.         'Score' = (($scores[$i] -split("/`">","")[0] -replace("&nbsp;"," "))[-1] -split("</a>"))[0]
  51.     }
  52.  
  53.     $obj = New-Object -TypeName psobject -Property $properties
  54.     $Match_stats.Add($obj)
  55. }
  56.  
  57. $outfile = "$($env:USERPROFILE)\desktop\SuperLigaData.csv"
  58. $Matchfile = "$($env:USERPROFILE)\desktop\SuperLigaDataRunder.csv"
  59.  
  60. $game_stats | Export-Csv -Path $outfile -Delimiter ';' -NoTypeInformation -Encoding UTF8 -Force
  61. $match_stats | Export-Csv -Path $MatchFile -Delimiter ';' -NoTypeInformation -Encoding UTF8 -Force
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement