I have a list like this:
<ol class="CricketPlayers">
<li id="1">Player: John, TotalRuns: 4350, AllRounder: false</li>
<li id="2">Player: Michael, TotalRuns: 8373, AllRounder: true</li>
</ol>
I need to convert this into JSON like this:
[
{
"Player": "John",
"TotalRuns": 4350,
"AllRounder": false
},
{
"Player": "Michael",
"TotalRuns": 8373,
"AllRounder": true
}
]
Formatting of JSON is not important.
Using jQuery etc. is not an option. I am thinking to convert the list into array and then calling JSON.stringify. But I not sure if that will work because there can be many items in the list.
.CricketPlayers, pull thetextout of each<li>, split on,(and hope there are no other commas), iterate over those and split on:and use each pair as a property name/value. This is why web scraping is awful--can you just get the data instead?