我想知道这段时期某些国家的人口1960-2015
。
我找到了这个包含这些数据的网站,我有兴趣使用Node.js
.
我读到有一些API,但我不明白如何使用它们。
我去了这个网站(它允许你创建和下载XML
格式的查询),我寻找了我感兴趣的表格。我设置了我感兴趣的参数并下载了查询:
<?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>
现在我必须做一个 HTTP Post 请求。我安装request-promise 包。
现在我不知道该怎么办。我考虑过使用这段代码,但我在哪里插入下载的查询?
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...
});
}
有人能帮我吗?