I have to iterate through a table and create a json object containing info in this way:
var obj = {
vaccine: "...",
year: ...,
country: "...",
coverage: ...
}
The table is:
<table class="ts">
<tr>
<td class="statheadings" colspan="100%" align="center">
<h1 class="statistics">Coverage time series for Italy (ITA)</h1>
</td>
</tr>
<tr>
<td align="center" colspan="100%"> <font color="red">
Last updated 06-Sep-2017 (data as of 05-Sep-2017)<br />Next overall update 2018<br /></font>
</td>
</tr>
<tr>
<td colspan="100%" >
<hr />
</td>
</tr>
<tr>
<th colspan="4" align="left">Vacciness</th>
<th class="year">2016</th>
<th class="year">2015</th>
<th class="year">2014</th>
<th class="year">2013</th>
<th class="year">2012</th>
<th class="year">2011</th>
<th class="year">2010</th>
<th class="year">2009</th>
<th class="year">2008</th>
<th class="year">2007</th>
<th class="year">2006</th>
<th class="year">2005</th>
<th class="year">2004</th>
<th class="year">2003</th>
<th class="year">2002</th>
<th class="year">2001</th>
<th class="year">2000</th>
<th class="year">1999</th>
<th class="year">1998</th>
<th class="year">1997</th>
<th class="year">1996</th>
<th class="year">1995</th>
<th class="year">1994</th>
<th class="year">1993</th>
<th class="year">1992</th>
<th class="year">1991</th>
<th class="year">1990</th>
<th class="year">1989</th>
<th class="year">1988</th>
<th class="year">1987</th>
<th class="year">1986</th>
<th class="year">1985</th>
<th class="year">1984</th>
<th class="year">1983</th>
<th class="year">1982</th>
<th class="year">1981</th>
</tr>
<tr class="odd">
<td colspan="4" align="left">
<a href="timeseries/tscoveragedtp3.html" title="Click for full global time series for DTP3">DTP3</a>
</td>
<td class="statistics_small" colspan="1">_ </td>
<td class="statistics_small" colspan="1">93 </td>
<td class="statistics_small" colspan="1">95 </td>
<td class="statistics_small" colspan="1">96 </td>
<td class="statistics_small" colspan="1">97 </td>
<td class="statistics_small" colspan="1">96 </td>
<td class="statistics_small" colspan="1">96 </td>
<td class="statistics_small" colspan="1">96 </td>
<td class="statistics_small" colspan="1">96 </td>
<td class="statistics_small" colspan="1">97 </td>
<td class="statistics_small" colspan="1">96 </td>
<td class="statistics_small" colspan="1">95 </td>
<td class="statistics_small" colspan="1">94 </td>
<td class="statistics_small" colspan="1">96 </td>
<td class="statistics_small" colspan="1">93 </td>
<td class="statistics_small" colspan="1">93 </td>
<td class="statistics_small" colspan="1">87 </td>
<td class="statistics_small" colspan="1">87 </td>
<td class="statistics_small" colspan="1">86 </td>
<td class="statistics_small" colspan="1">85 </td>
<td class="statistics_small" colspan="1">84 </td>
<td class="statistics_small" colspan="1">84 </td>
<td class="statistics_small" colspan="1">83 </td>
<td class="statistics_small" colspan="1">82 </td>
<td class="statistics_small" colspan="1">80 </td>
<td class="statistics_small" colspan="1">80 </td>
<td class="statistics_small" colspan="1">80 </td>
<td class="statistics_small" colspan="1">_ </td>
<td class="statistics_small" colspan="1">_ </td>
<td class="statistics_small" colspan="1">_ </td>
<td class="statistics_small" colspan="1">_ </td>
<td class="statistics_small" colspan="1">_ </td>
<td class="statistics_small" colspan="1">_ </td>
<td class="statistics_small" colspan="1">_ </td>
<td class="statistics_small" colspan="1">_ </td>
<td class="statistics_small" colspan="1">_ </td>
<tr class="even">
<td colspan="4" align="left">
<a href="timeseries/tscoveragehepb3.html" title="Click for full global time series for HepB3">HepB3</a>
</td>
<td class="statistics_small" colspan="1">
_
</td>
<td class="statistics_small" colspan="1">
93
</td>
<td class="statistics_small" colspan="1">
95
</td>
<td class="statistics_small" colspan="1">
96
</td>
<td class="statistics_small" colspan="1">
96
</td>
<td class="statistics_small" colspan="1">
96
</td>
<td class="statistics_small" colspan="1">
96
</td>
<td class="statistics_small" colspan="1">
96
</td>
<td class="statistics_small" colspan="1">
96
</td>
<td class="statistics_small" colspan="1">
97
</td>
<td class="statistics_small" colspan="1">
96
</td>
<td class="statistics_small" colspan="1">
96
</td>
<td class="statistics_small" colspan="1">
96
</td>
<td class="statistics_small" colspan="1">
95
</td>
<td class="statistics_small" colspan="1">
95
</td>
<td class="statistics_small" colspan="1">
95
</td>
<td class="statistics_small" colspan="1">
94
</td>
<td class="statistics_small" colspan="1">
94
</td>
<td class="statistics_small" colspan="1">
95
</td>
<td class="statistics_small" colspan="1">
95
</td>
<td class="statistics_small" colspan="1">
95
</td>
<td class="statistics_small" colspan="1">
95
</td>
<td class="statistics_small" colspan="1">
95
</td>
<td class="statistics_small" colspan="1">
95
</td>
<td class="statistics_small" colspan="1">
95
</td>
<td class="statistics_small" colspan="1">
50
</td>
<td class="statistics_small" colspan="1">
_
</td>
<td class="statistics_small" colspan="1">
_
</td>
<td class="statistics_small" colspan="1">
_
</td>
<td class="statistics_small" colspan="1">
_
</td>
<td class="statistics_small" colspan="1">
_
</td>
<td class="statistics_small" colspan="1">
_
</td>
<td class="statistics_small" colspan="1">
_
</td>
<td class="statistics_small" colspan="1">
_
</td>
<td class="statistics_small" colspan="1">
_
</td>
<td class="statistics_small" colspan="1">
_
</td>
<tr class="odd">
<td colspan="4" align="left">
<a href="timeseries/tscoveragedtp3.html" title="Click for full global time series for DTP3">DTP3</a>
</td>
...
As you can see, rows are divided in odd
and even
.
I took this table using Node.js
, Express.js
and Cheerio
.
This is my code:
const cheerio = require('cheerio');
const express = require('express');
var fs = require('fs');
const request = require('request');
const app = express();
// piece of link of each country
/*var countries = {
'Albania': 'ALB',
'Austria': 'AUT',
'Belgium': 'BEL',
'Bulgaria': 'BGR',
'Croatia': 'HRV',
'Cyprus': 'CYP',
'Denmark': 'DNK',
'Estonia': 'EST',
'Finland': 'FIN',
'France': 'FRA',
'Germany': 'DEU',
'Greece': 'GRC',
'Iceland': 'ISL',
'Ireland': 'IRL',
'Italy': 'ITA',
'Latvia': 'LVA',
'Netherlands': 'NLD',
'Norway': 'NOR',
'Poland': 'POL',
'Portugal': 'PRT',
'Romania': 'ROU',
'Slovakia': 'SVK',
'Slovenia': 'SVN',
'Spain': 'ESP',
'Sweden': 'SWE',
'Switzerland': 'CHE',
'United Kingdom': 'GBR'
};*/
// for test
var countries = {
'Albania': 'ALB'
};
// create variables to create json object
var jsons = [];
var json = {vaccine: "", country: "", year: "", coverage: ""};
for(country in countries) {
var url = 'http://apps.who.int/immunization_monitoring/globalsummary/coverages?c=' + countries[country];
request(url, (function(country) {
var thisCountry = country;
return function(error, res, html) {
if(error) {
console.log(error);
throw error;
}
// send html response to cheerio to create DOM
$ = cheerio.load(html);
// arrays containing all the values
var years = [];
var vaccines = [];
var coverages = [];
var i = 1;
// scraping year values
$('.ts .year').each(function(year) {
var country = thisCountry.trim();
var year = $(this).text().trim();
years.push(year);
json.country = country;
json.year = year;
});
console.log(years, years.length);
// scraping vaccine values
$('.ts .odd td a').each(function(odd) {
var vaccine = $(this).text().trim();
vaccines.push(vaccine);
json.vaccine = vaccine;
});
$('.ts .even td a').each(function(even) {
var vaccine = $(this).text().trim();
vaccines.push(vaccine);
json.vaccine = vaccine;
});
console.log(vaccines, vaccines.length);
// scraping coverage values (get all values)
$('.ts .odd .statistics_small').each(function(oddCoverage) {
var coverage = $(this).text().trim();
coverages.push(coverage);
});
$('.ts .even .statistics_small').each(function(evenCoverage) {
var coverage = $(this).text().trim();
coverages.push(coverage);
});
console.log(coverages, coverages.length);
console.log("i", i); // 1
// scraping coverage values (geto only some values)
$('.ts .odd:nth-child(' + i + ')').each(function(oddCoverage) {
var coverage = $(this).text().trim();
json.coverage = coverage;
});
i++;
console.log("i", i); // 2
jsons.push(json);
// write jsons on file output.json
fs.writeFile('output.json', JSON.stringify(jsons, null, 3), function(error) {
console.log('File output.json successfully written!');
});
console.log("i", i); // 2
} // end return
})(country)); // end request
}
The code doesn't work.
I'm able to retrieve all the years, all the vaccines and all the coverage values. But all these values are confused and mixed up.
I'm not sure how to build a json file containing all the orderd and structured values. My goal is a file like that:
[
{
"vaccine": "BCG",
"country": "Albania",
"year": 2016,
"coverage": 99
},
{
"vaccine": "BCG",
"country": "Albania",
"year": 2015,
"coverage": 100
},
{
"vaccine": "BCG",
"country": "Albania",
"year": 2014,
"coverage": 100
},
{
...
},
{
"vaccine": "BCG",
"country": "Albania",
"year": 1981,
"coverage": 93
},
{
"vaccine": "DTP1",
"country": "Albania",
"year": 2016,
"coverage": 99
},
{
...
},
{
"vaccine": "DTP1",
"country": "Albania",
"year": 1981,
"coverage": _
},
{
"vaccine": "TT2+",
"country": "Albania",
"year": 2016,
"coverage": _
},
{
...
},
{
"vaccine": "TT2+",
"country": "Albania",
"year": 1981,
"coverage": _
},
{
"vaccine": "BCG",
"country": "Austria",
"year": 2016,
"coverage": _
},
{
...
}
]
It have to contain 576 = 36*16
elements.
I try to create an index i
to iterate through td
element but it doesn't work.
Now, my output.js
file is:
[
{
"vaccine": "TT2+",
"country": "Albania",
"year": "1981",
"coverage": ""
}
]
Thanks!
EDIT
My goal is costruct a json object from a table.
The table:
<table class="ts">
<tr>
<td class="statheadings" colspan="100%" align="center">
<h1 class="statistics">Coverage time series for Italy (ITA)</h1>
</td>
</tr>
<tr>
<td align="center" colspan="100%"> <font color="red">
Last updated 06-Sep-2017 (data as of 05-Sep-2017)<br />Next overall update 2018<br /></font>
</td>
</tr>
<tr>
<td colspan="100%" >
<hr />
</td>
</tr>
<tr>
<th colspan="4" align="left">Vacciness</th>
<th class="year">2016</th>
<th class="year">2015</th>
<th class="year">2014</th>
<th class="year">2013</th>
<th class="year">2012</th>
<th class="year">2011</th>
<th class="year">2010</th>
<th class="year">2009</th>
<th class="year">2008</th>
<th class="year">2007</th>
<th class="year">2006</th>
<th class="year">2005</th>
<th class="year">2004</th>
<th class="year">2003</th>
<th class="year">2002</th>
<th class="year">2001</th>
<th class="year">2000</th>
<th class="year">1999</th>
<th class="year">1998</th>
<th class="year">1997</th>
<th class="year">1996</th>
<th class="year">1995</th>
<th class="year">1994</th>
<th class="year">1993</th>
<th class="year">1992</th>
<th class="year">1991</th>
<th class="year">1990</th>
<th class="year">1989</th>
<th class="year">1988</th>
<th class="year">1987</th>
<th class="year">1986</th>
<th class="year">1985</th>
<th class="year">1984</th>
<th class="year">1983</th>
<th class="year">1982</th>
<th class="year">1981</th>
</tr>
<tr class="odd">
<td colspan="4" align="left">
<a href="timeseries/tscoveragedtp3.html" title="Click for full global time series for DTP3">DTP3</a>
</td>
<td class="statistics_small" colspan="1">_ </td>
<td class="statistics_small" colspan="1">93 </td>
<td class="statistics_small" colspan="1">95 </td>
<td class="statistics_small" colspan="1">96 </td>
<td class="statistics_small" colspan="1">97 </td>
<td class="statistics_small" colspan="1">96 </td>
<td class="statistics_small" colspan="1">96 </td>
<td class="statistics_small" colspan="1">96 </td>
<td class="statistics_small" colspan="1">96 </td>
<td class="statistics_small" colspan="1">97 </td>
<td class="statistics_small" colspan="1">96 </td>
<td class="statistics_small" colspan="1">95 </td>
<td class="statistics_small" colspan="1">94 </td>
<td class="statistics_small" colspan="1">96 </td>
<td class="statistics_small" colspan="1">93 </td>
<td class="statistics_small" colspan="1">93 </td>
<td class="statistics_small" colspan="1">87 </td>
<td class="statistics_small" colspan="1">87 </td>
<td class="statistics_small" colspan="1">86 </td>
<td class="statistics_small" colspan="1">85 </td>
<td class="statistics_small" colspan="1">84 </td>
<td class="statistics_small" colspan="1">84 </td>
<td class="statistics_small" colspan="1">83 </td>
<td class="statistics_small" colspan="1">82 </td>
<td class="statistics_small" colspan="1">80 </td>
<td class="statistics_small" colspan="1">80 </td>
<td class="statistics_small" colspan="1">80 </td>
<td class="statistics_small" colspan="1">_ </td>
<td class="statistics_small" colspan="1">_ </td>
<td class="statistics_small" colspan="1">_ </td>
<td class="statistics_small" colspan="1">_ </td>
<td class="statistics_small" colspan="1">_ </td>
<td class="statistics_small" colspan="1">_ </td>
<td class="statistics_small" colspan="1">_ </td>
<td class="statistics_small" colspan="1">_ </td>
<td class="statistics_small" colspan="1">_ </td>
<tr class="even">
<td colspan="4" align="left">
<a href="timeseries/tscoveragehepb3.html" title="Click for full global time series for HepB3">HepB3</a>
</td>
<td class="statistics_small" colspan="1">
_
</td>
<td class="statistics_small" colspan="1">
93
</td>
<td class="statistics_small" colspan="1">
95
</td>
<td class="statistics_small" colspan="1">
96
</td>
<td class="statistics_small" colspan="1">
96
</td>
<td class="statistics_small" colspan="1">
96
</td>
<td class="statistics_small" colspan="1">
96
</td>
<td class="statistics_small" colspan="1">
96
</td>
<td class="statistics_small" colspan="1">
96
</td>
<td class="statistics_small" colspan="1">
97
</td>
<td class="statistics_small" colspan="1">
96
</td>
<td class="statistics_small" colspan="1">
96
</td>
<td class="statistics_small" colspan="1">
96
</td>
<td class="statistics_small" colspan="1">
95
</td>
<td class="statistics_small" colspan="1">
95
</td>
<td class="statistics_small" colspan="1">
95
</td>
<td class="statistics_small" colspan="1">
94
</td>
<td class="statistics_small" colspan="1">
94
</td>
<td class="statistics_small" colspan="1">
95
</td>
<td class="statistics_small" colspan="1">
95
</td>
<td class="statistics_small" colspan="1">
95
</td>
<td class="statistics_small" colspan="1">
95
</td>
<td class="statistics_small" colspan="1">
95
</td>
<td class="statistics_small" colspan="1">
95
</td>
<td class="statistics_small" colspan="1">
95
</td>
<td class="statistics_small" colspan="1">
50
</td>
<td class="statistics_small" colspan="1">
_
</td>
<td class="statistics_small" colspan="1">
_
</td>
<td class="statistics_small" colspan="1">
_
</td>
<td class="statistics_small" colspan="1">
_
</td>
<td class="statistics_small" colspan="1">
_
</td>
<td class="statistics_small" colspan="1">
_
</td>
<td class="statistics_small" colspan="1">
_
</td>
<td class="statistics_small" colspan="1">
_
</td>
<td class="statistics_small" colspan="1">
_
</td>
<td class="statistics_small" colspan="1">
_
</td>
<tr class="odd">
<td colspan="4" align="left">
<a href="timeseries/tscoveragedtp3.html" title="Click for full global time series for DTP3">DTP3</a>
</td>
...
The json object I want:
[
{
"vaccine": "BCG",
"country": "Albania",
"year": 2016,
"coverage": 99
},
{
"vaccine": "BCG",
"country": "Albania",
"year": 2015,
"coverage": 100
},
{
"vaccine": "BCG",
"country": "Albania",
"year": 2014,
"coverage": 100
},
{
...
},
{
"vaccine": "BCG",
"country": "Albania",
"year": 1981,
"coverage": 93
},
{
"vaccine": "DTP1",
"country": "Albania",
"year": 2016,
"coverage": 99
},
{
...
},
{
"vaccine": "DTP1",
"country": "Albania",
"year": 1981,
"coverage": _
},
{
"vaccine": "TT2+",
"country": "Albania",
"year": 2016,
"coverage": _
},
{
...
},
{
"vaccine": "TT2+",
"country": "Albania",
"year": 1981,
"coverage": _
},
{
"vaccine": "BCG",
"country": "Austria",
"year": 2016,
"coverage": _
},
{
...
}
]
I simplified your parsing code a bit. It works fine on my machine. The problem with your code was that while you were pushing all the values into arrays, you weren't using those values to build up your desired objects. My parsing strategy: grab all the data in three separate arrays just like you did, and then iterate over these arrays to generate the desired object structure.
I tested it locally over the first two countries in your countries object and it was successful.
Here's the code I changed in your for(country in countries)
loop:
var years = [];
var vaccines = [];
var coverages = [];
// get years
$('.ts .year').each(function() {
years.push($(this).text().trim());
});
// get vaccines
$('.ts .odd td a, .ts .even td a').each(function() {
vaccines.push($(this).text().trim());
});
// get coverages
$('.ts .odd .statistics_small, .ts .even .statistics_small').each(function() {
coverages.push($(this).text().trim());
});
const numYears = years.length;
const numVaccines = vaccines.length;
for (var vaccineIdx=0; vaccineIdx<numVaccines; vaccineIdx++) {
// iterate over each vaccine
for (var yearIdx=0; yearIdx<numYears; yearIdx++) {
//iterate over each year for vaccine
let obj = {
vaccine: vaccines[vaccineIdx],
country: country,
year: years[yearIdx],
coverage: coverages[vaccineIdx*numYears+yearIdx]
}
jsons.push(obj);
}
}
// write jsons on file output.json
fs.writeFile('output.json', JSON.stringify(jsons, null, 3), function(error) {
if (!error) { console.log('File output.json successfully written with',country,'data!'); }
else {
console.log(error, 'occurred while trying to write',country,'data to output.json');
}
});
Resulting object for first and last (BCG and TT2+ vaccines) for Albania (intermediate values in array omitted because of StackOverflow limitations):
[
{
"vaccine": "BCG",
"country": "Albania",
"year": "2016",
"coverage": "99"
},
{
"vaccine": "BCG",
"country": "Albania",
"year": "2015",
"coverage": "100"
},
{
"vaccine": "BCG",
"country": "Albania",
"year": "2014",
"coverage": "100"
},
{
"vaccine": "BCG",
"country": "Albania",
"year": "2013",
"coverage": "100"
},
{
"vaccine": "BCG",
"country": "Albania",
"year": "2012",
"coverage": "96"
},
{
"vaccine": "BCG",
"country": "Albania",
"year": "2011",
"coverage": "97"
},
{
"vaccine": "BCG",
"country": "Albania",
"year": "2010",
"coverage": "100"
},
{
"vaccine": "BCG",
"country": "Albania",
"year": "2009",
"coverage": "97"
},
{
"vaccine": "BCG",
"country": "Albania",
"year": "2008",
"coverage": "100"
},
{
"vaccine": "BCG",
"country": "Albania",
"year": "2007",
"coverage": "98"
},
{
"vaccine": "BCG",
"country": "Albania",
"year": "2006",
"coverage": "97"
},
{
"vaccine": "BCG",
"country": "Albania",
"year": "2005",
"coverage": "98"
},
{
"vaccine": "BCG",
"country": "Albania",
"year": "2004",
"coverage": "97"
},
{
"vaccine": "BCG",
"country": "Albania",
"year": "2003",
"coverage": "95"
},
{
"vaccine": "BCG",
"country": "Albania",
"year": "2002",
"coverage": "94"
},
{
"vaccine": "BCG",
"country": "Albania",
"year": "2001",
"coverage": "93"
},
{
"vaccine": "BCG",
"country": "Albania",
"year": "2000",
"coverage": "93"
},
{
"vaccine": "BCG",
"country": "Albania",
"year": "1999",
"coverage": "93"
},
{
"vaccine": "BCG",
"country": "Albania",
"year": "1998",
"coverage": "87"
},
{
"vaccine": "BCG",
"country": "Albania",
"year": "1997",
"coverage": "94"
},
{
"vaccine": "BCG",
"country": "Albania",
"year": "1996",
"coverage": "94"
},
{
"vaccine": "BCG",
"country": "Albania",
"year": "1995",
"coverage": "97"
},
{
"vaccine": "BCG",
"country": "Albania",
"year": "1994",
"coverage": "87"
},
{
"vaccine": "BCG",
"country": "Albania",
"year": "1993",
"coverage": "82"
},
{
"vaccine": "BCG",
"country": "Albania",
"year": "1992",
"coverage": "81"
},
{
"vaccine": "BCG",
"country": "Albania",
"year": "1991",
"coverage": "80"
},
{
"vaccine": "BCG",
"country": "Albania",
"year": "1990",
"coverage": "94"
},
{
"vaccine": "BCG",
"country": "Albania",
"year": "1989",
"coverage": "94"
},
{
"vaccine": "BCG",
"country": "Albania",
"year": "1988",
"coverage": "92"
},
{
"vaccine": "BCG",
"country": "Albania",
"year": "1987",
"coverage": "92"
},
{
"vaccine": "BCG",
"country": "Albania",
"year": "1986",
"coverage": "92"
},
{
"vaccine": "BCG",
"country": "Albania",
"year": "1985",
"coverage": "92"
},
{
"vaccine": "BCG",
"country": "Albania",
"year": "1984",
"coverage": "90"
},
{
"vaccine": "BCG",
"country": "Albania",
"year": "1983",
"coverage": "90"
},
{
"vaccine": "BCG",
"country": "Albania",
"year": "1982",
"coverage": "_"
},
{
"vaccine": "BCG",
"country": "Albania",
"year": "1981",
"coverage": "93"
},
{
"vaccine": "TT2+",
"country": "Albania",
"year": "2016",
"coverage": "_"
},
{
"vaccine": "TT2+",
"country": "Albania",
"year": "2015",
"coverage": "_"
},
{
"vaccine": "TT2+",
"country": "Albania",
"year": "2014",
"coverage": "_"
},
{
"vaccine": "TT2+",
"country": "Albania",
"year": "2013",
"coverage": "_"
},
{
"vaccine": "TT2+",
"country": "Albania",
"year": "2012",
"coverage": "_"
},
{
"vaccine": "TT2+",
"country": "Albania",
"year": "2011",
"coverage": "75"
},
{
"vaccine": "TT2+",
"country": "Albania",
"year": "2010",
"coverage": "85"
},
{
"vaccine": "TT2+",
"country": "Albania",
"year": "2009",
"coverage": "80"
},
{
"vaccine": "TT2+",
"country": "Albania",
"year": "2008",
"coverage": "83"
},
{
"vaccine": "TT2+",
"country": "Albania",
"year": "2007",
"coverage": "86"
},
{
"vaccine": "TT2+",
"country": "Albania",
"year": "2006",
"coverage": "86"
},
{
"vaccine": "TT2+",
"country": "Albania",
"year": "2005",
"coverage": "86"
},
{
"vaccine": "TT2+",
"country": "Albania",
"year": "2004",
"coverage": "85"
},
{
"vaccine": "TT2+",
"country": "Albania",
"year": "2003",
"coverage": "73"
},
{
"vaccine": "TT2+",
"country": "Albania",
"year": "2002",
"coverage": "71"
},
{
"vaccine": "TT2+",
"country": "Albania",
"year": "2001",
"coverage": "80"
},
{
"vaccine": "TT2+",
"country": "Albania",
"year": "2000",
"coverage": "89"
},
{
"vaccine": "TT2+",
"country": "Albania",
"year": "1999",
"coverage": "77"
},
{
"vaccine": "TT2+",
"country": "Albania",
"year": "1998",
"coverage": "65"
},
{
"vaccine": "TT2+",
"country": "Albania",
"year": "1997",
"coverage": "99"
},
{
"vaccine": "TT2+",
"country": "Albania",
"year": "1996",
"coverage": "98"
},
{
"vaccine": "TT2+",
"country": "Albania",
"year": "1995",
"coverage": "97"
},
{
"vaccine": "TT2+",
"country": "Albania",
"year": "1994",
"coverage": "100"
},
{
"vaccine": "TT2+",
"country": "Albania",
"year": "1993",
"coverage": "96"
},
{
"vaccine": "TT2+",
"country": "Albania",
"year": "1992",
"coverage": "94"
},
{
"vaccine": "TT2+",
"country": "Albania",
"year": "1991",
"coverage": "78"
},
{
"vaccine": "TT2+",
"country": "Albania",
"year": "1990",
"coverage": "_"
},
{
"vaccine": "TT2+",
"country": "Albania",
"year": "1989",
"coverage": "_"
},
{
"vaccine": "TT2+",
"country": "Albania",
"year": "1988",
"coverage": "_"
},
{
"vaccine": "TT2+",
"country": "Albania",
"year": "1987",
"coverage": "_"
},
{
"vaccine": "TT2+",
"country": "Albania",
"year": "1986",
"coverage": "_"
},
{
"vaccine": "TT2+",
"country": "Albania",
"year": "1985",
"coverage": "_"
},
{
"vaccine": "TT2+",
"country": "Albania",
"year": "1984",
"coverage": "_"
},
{
"vaccine": "TT2+",
"country": "Albania",
"year": "1983",
"coverage": "_"
},
{
"vaccine": "TT2+",
"country": "Albania",
"year": "1982",
"coverage": "_"
},
{
"vaccine": "TT2+",
"country": "Albania",
"year": "1981",
"coverage": "_"
}
]
This parsing code is a little bit fragile: if the site you are scraping from changes its class values or has differing structure on different country's pages, the data could be invalid. Depending on the scope and intent of your project, this may or may not be a concern. Just something to consider.