Last active
August 29, 2015 14:13
-
-
Save coolicer/548075a7a8a4c3ac75a1 to your computer and use it in GitHub Desktop.
get-weather-from-baidu
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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