node.js 中国天气预报 简单实现
Coolicer 人气:0复制代码 代码如下:
var request = require('request')
var url = 'http://www.baidu.com/home/xmanhttps://img.qb5200.com/download-x/data/superload'
var cookie = '你登录百度后的cookie'
var options = {
method: "GET",
url: url,
qs: {
"type": "weather",
"asyn": 1,
"t": new Date().getTime()
},
headers: {
'User-Agent': 'Mozilla/5.0 (Windows NT 6.3; WOW64; rv:34.0) Gecko/20100101 Firefox/34.0',
'Cookie': cookie
}
};
function callback(error, response, body) {
if (!error && response.statusCode == 200) {
var info = JSON.parse(body);
console.log(info);
}
}
request(options, callback);
var url = 'http://www.baidu.com/home/xmanhttps://img.qb5200.com/download-x/data/superload'
var cookie = '你登录百度后的cookie'
var options = {
method: "GET",
url: url,
qs: {
"type": "weather",
"asyn": 1,
"t": new Date().getTime()
},
headers: {
'User-Agent': 'Mozilla/5.0 (Windows NT 6.3; WOW64; rv:34.0) Gecko/20100101 Firefox/34.0',
'Cookie': cookie
}
};
function callback(error, response, body) {
if (!error && response.statusCode == 200) {
var info = JSON.parse(body);
console.log(info);
}
}
request(options, callback);
当你登录百度,是不是会显示一个天气。我们可以利用这个API做一个小插件,上面的代码很少。希望能给大家一个参考,也希望大家多多支持。
加载全部内容