Reputation: 31
I'm trying to scrape a website to keep track of my ranking in a Rocket League playlist over time automatically. The idea being that I'd grab the number corresponding to my playlist and put it in a csv for tacking purposes. I've been able to get the Html for the webpage but can't seem to parse it effectively for the number I'm after.
Here's how I've gathered the webpage info:
$tracker = Invoke-WebRequest -Uri
https://rocketleague.tracker.network/profile/steam/adammast12
$tracker.RawContent
Here's the section of the RawContent that is of interest to me:
<script type="text/javascript">
$('#playlist-tracking-rating').highcharts({
chart: {
type: 'line',
zoomType: 'xy'
},
title: {
text: 'Rating Progression'
},
xAxis: {
categories: ['Nov 05','Nov 08','Nov 10','Nov 11','Nov 12','Nov 13'],
type: 'date',
},
yAxis: {
title: {
text: 'Rating'
}
},
tooltip: {
enabled: true,
shared: true
},
plotOptions: {
line: {
dataLabels: {
enabled: true
},
enableMouseTracking: true
}
},
series: [
{ name: 'Un-Ranked', data: [1270,1270,1270,1270,1270,1251] },
{ name: 'Ranked Duel 1v1', data: [655,655,655,655,655,655] },
{ name: 'Ranked Doubles 2v2', data: [815,775,856,847,865,865] },
{ name: 'Ranked Solo Standard 3v3', data: [788,788,788,788,788,788] },
{ name: 'Ranked Standard 3v3', data: [994,994,994,994,994,994] },
{ name: 'Hoops', data: [556,556,556,556,525,525] },
{ name: 'Rumble', data: [651,741,703,703,704,704] },
{ name: 'Dropshot', data: [635,635,635,635,635,635] },
{ name: 'Snowday', data: [770,770] },
]
});
$('#playlist-tracking').highcharts({
chart: {
type: 'spline',
zoomType: 'xy'
},
title: {
text: 'Tier Over Time'
},
subtitle: {
text: ''
},
xAxis: {
categories: ['Nov 05','Nov 08','Nov 10','Nov 11','Nov 12','Nov 13'],
type: 'date',
labels: {
overflow: 'justify'
}
},
tooltip: {
enabled: true,
shared: true
},
yAxis: {
title: {
text: ''
},
labels: {
enabled: false
},
minorGridLineWidth: 0,
gridLineWidth: 0,
alternateGridColor: null,
plotBands: [{
from: 0,
to: 0.99,
color: 'rgba(75, 75, 75, 0.1)',
label: {
text: 'Unranked',
style: {
color: '#606060'
}
}
}, {
from: 1,
to: 1.99,
color: 'rgba(227, 150, 68, 0.1',
label: {
text: 'Bronze I',
style: {
color: '#606060'
}
}
}, {
from: 2,
to: 2.99,
color: 'rgba(227, 150, 68, 0.1)',
label: {
text: 'Bronze II',
style: {
color: '#606060'
}
}
}, {
from: 3,
to: 3.99,
color: 'rgba(227, 150, 68, 0.1)',
label: {
text: 'Bronze III',
style: {
color: '#606060'
}
}
}, {
from: 4,
to: 4.99,
color: 'rgba(197, 197, 197, 0.1)',
label: {
text: 'Silver I',
style: {
color: '#606060'
}
}
}, {
from: 5,
to: 5.99,
color: 'rgba(197, 197, 197, 0.1)',
label: {
text: 'Silver II',
style: {
color: '#606060'
}
}
}, {
from: 6,
to: 6.99,
color: 'rgba(197, 197, 197, 0.1)',
label: {
text: 'Silver III',
style: {
color: '#606060'
}
}
}, {
from: 7,
to: 7.99,
color: 'rgba(206, 163, 32, 0.1)',
label: {
text: 'Gold I',
style: {
color: '#606060'
}
}
}, {
from: 8,
to: 8.99,
color: 'rgba(206, 163, 32, 0.1)',
label: {
text: 'Gold II',
style: {
color: '#606060'
}
}
}, {
from: 9,
to: 9.99,
color: 'rgba(206, 163, 32, 0.1)',
label: {
text: 'Gold III',
style: {
color: '#606060'
}
}
}, {
from: 10,
to: 10.99,
color: 'rgba(37, 161, 213, 0.1)',
label: {
text: 'Platinum I',
style: {
color: '#606060'
}
}
}, {
from: 11,
to: 11.99,
color: 'rgba(37, 161, 213, 0.1)',
label: {
text: 'Platinum II',
style: {
color: '#606060'
}
}
}, {
from: 12,
to: 12.99,
color: 'rgba(37, 161, 213, 0.1)',
label: {
text: 'Platinum III',
style: {
color: '#606060'
}
}
}, {
from: 13,
to: 13.99,
color: 'rgba(0, 79, 182, 0.1)',
label: {
text: 'Diamond I',
style: {
color: '#606060'
}
}
}, {
from: 14,
to: 14.99,
color: 'rgba(0, 79, 182, 0.1)',
label: {
text: 'Diamond II',
style: {
color: '#606060'
}
}
}, {
from: 15,
to: 15.99,
color: 'rgba(0, 79, 182, 0.1)',
label: {
text: 'Diamond III',
style: {
color: '#606060'
}
}
}, {
from: 15,
to: 15.99,
color: 'rgba(142, 89, 225, 0.1)',
label: {
text: 'Champion I',
style: {
color: '#606060'
}
}
}, {
from: 15,
to: 15.99,
color: 'rgba(142, 89, 225, 0.1)',
label: {
text: 'Champion II',
style: {
color: '#606060'
}
}
}, {
from: 15,
to: 15.99,
color: 'rgba(142, 89, 225, 0.1)',
label: {
text: 'Champion III',
style: {
color: '#606060'
}
}
}, {
from: 15,
to: 15.99,
color: 'rgba(249, 135, 254, 0.1)',
label: {
text: 'Grand Champion',
style: {
color: '#606060'
}
}
}]
},
plotOptions: {
spline: {
lineWidth: 4,
states: {
hover: {
lineWidth: 5
}
},
marker: {
enabled: false
}
}
},
navigation: {
menuItemStyle: {
fontSize: '10px'
}
},
series: [
{ name: 'Ranked Duel 1v1', data: [0,0,0,0,0,0] },
{ name: 'Ranked Doubles 2v2', data: [11,11,12,12,12,12] },
{ name: 'Ranked Solo Standard 3v3', data: [0,0,0,0,0,0] },
{ name: 'Ranked Standard 3v3', data: [0,0,0,0,0,0] },
{ name: 'Hoops', data: [0,0,0,0,0,0] },
{ name: 'Rumble', data: [0,11,11,11,11,11] },
{ name: 'Dropshot', data: [10,10,10,10,10,10] },
{ name: 'Snowday', data: [12,12] },
]
});
I'd like to get the information out of the series related to the ranked playlists. For example, I need to be able to get the first value corresponding to "Ranked Duel 1v1" and "Ranked Doubles 2v2" etc. so I can save that number in a csv.
I've tried searching by string like this:
$data = $tracker.tostring() -split "[`r`n]" | select-string "Ranked Standard 3v3"
Which gives me this as a result:
Ranked Standard 3v3
Ranked Standard 3v3
Ranked Standard 3v3
Ranked Standard 3v3
Ranked Standard 3v3
Ranked Standard 3v3
{ name: 'Ranked Standard 3v3', data:
[994,994,994,994,994,994] },
{ name: 'Ranked Standard 3v3', data: [0,0,0,0,0,0] },
I'm not sure how to parse it from there though. Thanks for any help!
Upvotes: 2
Views: 210
Reputation: 2308
Here's a sample of how to just get the 'Un-tracked' section:
# result ArrayList
$results = New-Object System.Collections.ArrayList
# REST Get
$tracker = Invoke-WebRequest -Uri https://rocketleague.tracker.network/profile/steam/adammast12
# HTML data
# $tracker.RawContent
# split by carriage return + new line
# select the JSON with "name:" in it
$data = $tracker.tostring() -split "`r`n" | Select-String "name:"
# Un-Ranked data
$unranked = $data | Select-String "name: 'Un-Ranked'"
# Split at []'s
$unrankedSplit = $unranked.ToString().Split('[').Split(']')
# this yields a result like this:
# { name: 'Un-Ranked', data:
# 1270,1270,1270,1270,1270,1251
# },
#
# Split again at the second position on each comma, position [1]
# since PowerShell is zero-based indexing
$unrankedSplitChild = $unrankedSplit[1].Split(',')
# loop through each item with custom objects
foreach($item in $unrankedSplitChild)
{
# create a PSCustomObject and add to to the results
$results += [PSCustomObject]@{Category="Un-Ranked";Data=$item}
}
# throw the results to the console
$results | Format-Table -AutoSize
Upvotes: 1