Skip to content

Instantly share code, notes, and snippets.

@coolicer
Last active August 29, 2015 14:13
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save coolicer/548075a7a8a4c3ac75a1 to your computer and use it in GitHub Desktop.
Save coolicer/548075a7a8a4c3ac75a1 to your computer and use it in GitHub Desktop.
get-weather-from-baidu
var http = require('http'),
querystring = require('querystring'),
host = 'www.baidu.com',
path = '/home/xman/data/superload?',
cookie = 'YOUR_LOGINED_COOKIE',
o = {
"type": "weather",
"asyn": 1,
"t": new Date().getTime()
},
options;
// concat querystring
path += querystring.stringify(o)
options = {
method: 'GET',
port: 80,
hostname: host,
path: path,
headers: {
'User-Agent': 'Mozilla/5.0 (Windows NT 6.3; WOW64; rv:34.0) Gecko/20100101 Firefox/34.0',
'Cookie': cookie
}
};
var req = http.request(options, callback)
req.on('error', function(e) {
console.log('problem with request: ' + e.message);
});
// write data to request body
req.write('data\n');
req.write('data\n');
req.end();
function callback(res) {
var str = ''
res.setEncoding('utf8')
res.on('data', function(chunk) {
str += chunk
})
res.on('end', function() {
console.log(JSON.parse(str))
})
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment