Skip to content

Instantly share code, notes, and snippets.

@LinZap
Created September 7, 2015 07:16
Show Gist options
  • Save LinZap/1f9ca815a1c378ada848 to your computer and use it in GitHub Desktop.
Save LinZap/1f9ca815a1c378ada848 to your computer and use it in GitHub Desktop.
姓名產生器爬蟲 (payload)
var http = require('http');
var fs = require('fs');
var iconv = require('iconv-lite');
var querystring = require('querystring');
var BufferHelper = require('bufferhelper');
// var url = "http://www.richyli.com/name/index.asp";
var params = {
name_count:1000,
"break":2,
yourname:""
};
PostCode(params);
function PostCode(pdata) {
// Build the post string from an object
var post_data = querystring.stringify(pdata);
// An object of options to indicate where to post to
var post_options = {
host: 'www.richyli.com',
port: '80',
path: '/name/index.asp' ,
method: 'POST',
headers: {
'Content-Type': 'application/x-www-form-urlencoded',
'Content-Length': post_data.length
}
};
// Set up the request
var post_req = http.request(post_options, function(res) {
var bufferhelper = new BufferHelper();
res.on('data', function (chunk) {
bufferhelper.concat(chunk);
});
res.on('end', function (){
var r = iconv.decode(bufferhelper.toBuffer(), 'Big5');
console.log(r);
fs.writeFileSync('page.html',r);
});
});
// post the data
post_req.write(post_data);
post_req.end();
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment