I want to know the population of some countries over the period 1960-2015
.
I found this site that contains this data and I'm interested in downloading it using Node.js
.
I read that there are some APIs but I didn't understand how to use them.
I went to this site (which allows you to create and download the query in XML
format) and I looked for the table that interests me.
I set the parameters that interest me and I downloaded the query:
<?xml version="1.0" encoding="utf-8"?>
<StructureSpecificDataQuery xmlns="http://www.sdmx.org/resources/sdmxml/schemas/v2_1/message">
<!--NSI Web client v3.11.0.0-->
<Header>
<ID>IDREF47</ID>
<Test>false</Test>
<Prepared>2018-04-07T10:31:11.2310882+02:00</Prepared>
<Sender id="Unknown" />
<Receiver id="Unknown" />
</Header>
<Query>
<ReturnDetails defaultLimit="361914" detail="Full" observationAction="Active" xmlns="http://www.sdmx.org/resources/sdmxml/schemas/v2_1/query">
<Structure dimensionAtObservation="TIME_PERIOD" structureID="StructureId">
<Structure xmlns="http://www.sdmx.org/resources/sdmxml/schemas/v2_1/common">
<Ref agencyID="WB" id="WDI" version="1.0" xmlns="" />
</Structure>
</Structure>
</ReturnDetails>
<DataWhere xmlns="http://www.sdmx.org/resources/sdmxml/schemas/v2_1/query">
<Dataflow>
<Ref agencyID="WB" id="DF_UNDATA_WDI" version="1.0" xmlns="" />
</Dataflow>
<TimeDimensionValue>
<TimeValue operator="greaterThanOrEqual">1960-01-01</TimeValue>
<TimeValue operator="lessThanOrEqual">2015-12-31</TimeValue>
</TimeDimensionValue>
<Or>
<DimensionValue>
<ID>SERIES</ID>
<Value operator="equal">SP_POP_TOTL</Value>
</DimensionValue>
</Or>
<Or>
<DimensionValue>
<ID>REF_AREA</ID>
<Value operator="equal">ALB</Value>
</DimensionValue>
<DimensionValue>
<ID>REF_AREA</ID>
<Value operator="equal">AUT</Value>
</DimensionValue>
<DimensionValue>
<ID>REF_AREA</ID>
<Value operator="equal">BEL</Value>
</DimensionValue>
<DimensionValue>
<ID>REF_AREA</ID>
<Value operator="equal">BGR</Value>
</DimensionValue>
<DimensionValue>
<ID>REF_AREA</ID>
<Value operator="equal">HRV</Value>
</DimensionValue>
<DimensionValue>
<ID>REF_AREA</ID>
<Value operator="equal">CYP</Value>
</DimensionValue>
<DimensionValue>
<ID>REF_AREA</ID>
<Value operator="equal">DNK</Value>
</DimensionValue>
<DimensionValue>
<ID>REF_AREA</ID>
<Value operator="equal">EST</Value>
</DimensionValue>
<DimensionValue>
<ID>REF_AREA</ID>
<Value operator="equal">FIN</Value>
</DimensionValue>
<DimensionValue>
<ID>REF_AREA</ID>
<Value operator="equal">FRA</Value>
</DimensionValue>
<DimensionValue>
<ID>REF_AREA</ID>
<Value operator="equal">DEU</Value>
</DimensionValue>
<DimensionValue>
<ID>REF_AREA</ID>
<Value operator="equal">GRC</Value>
</DimensionValue>
<DimensionValue>
<ID>REF_AREA</ID>
<Value operator="equal">ISL</Value>
</DimensionValue>
<DimensionValue>
<ID>REF_AREA</ID>
<Value operator="equal">ITA</Value>
</DimensionValue>
<DimensionValue>
<ID>REF_AREA</ID>
<Value operator="equal">LVA</Value>
</DimensionValue>
<DimensionValue>
<ID>REF_AREA</ID>
<Value operator="equal">NLD</Value>
</DimensionValue>
<DimensionValue>
<ID>REF_AREA</ID>
<Value operator="equal">NOR</Value>
</DimensionValue>
<DimensionValue>
<ID>REF_AREA</ID>
<Value operator="equal">POL</Value>
</DimensionValue>
<DimensionValue>
<ID>REF_AREA</ID>
<Value operator="equal">PRT</Value>
</DimensionValue>
<DimensionValue>
<ID>REF_AREA</ID>
<Value operator="equal">ROM</Value>
</DimensionValue>
<DimensionValue>
<ID>REF_AREA</ID>
<Value operator="equal">SVK</Value>
</DimensionValue>
<DimensionValue>
<ID>REF_AREA</ID>
<Value operator="equal">SVN</Value>
</DimensionValue>
<DimensionValue>
<ID>REF_AREA</ID>
<Value operator="equal">ESP</Value>
</DimensionValue>
<DimensionValue>
<ID>REF_AREA</ID>
<Value operator="equal">SWE</Value>
</DimensionValue>
<DimensionValue>
<ID>REF_AREA</ID>
<Value operator="equal">CHE</Value>
</DimensionValue>
<DimensionValue>
<ID>REF_AREA</ID>
<Value operator="equal">GBR</Value>
</DimensionValue>
<DimensionValue>
<ID>REF_AREA</ID>
<Value operator="equal">EMU</Value>
</DimensionValue>
<DimensionValue>
<ID>REF_AREA</ID>
<Value operator="equal">EUU</Value>
</DimensionValue>
</Or>
</DataWhere>
</Query>
</StructureSpecificDataQuery>
Now I have to do an HTTP Post request. I install request-promise package.
Now I don't know what to do. I thought about using this code, but where do I insert the downloaded query?
var cheerio = require('cheerio');
var request = require('request-promise');
var methods = {};
var options = {
uri: '???',
transform: function(body) {
return cheerio.load(body);
}
};
methods.download = async function(req, res) {
request(options)
.then(function($) {
// Process html like you would with jQuery...
})
.catch(function(err) {
// Crawling failed or Cheerio choked...
});
}
Can someone help me?