var request = require('request')
var url = 'http://www.baidu.com/home/xman/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做一个小插件,上面的代码很少。