nodejs实战:制作qq空间留言板留言机器人 【2016/11/14 亲测成功】
后面注释有修改项的记得注意和修改 var http = require('http') var querystring = require('querystring') var postDataObj = { 'qzreferrer':'http://qzs.qq.com/qzone/msgboard/msgbcanvas.html#page=1', 'content':'评论的内容',// 修改项 'hostUin':'被评论人的qq',// 修改项 'uin':'本人qq',// 修改项 'format':'fs', 'inCharset':'utf-8', 'outCharset':'utf-8', 'iNotice':'1', 'ref':'qzone', 'json':'1', 'g_tk':'990423949' } var options={ hostname:'h5.qzone.qq.com', port:80, path:'/proxy/domain/m.qzone.qq.com/cgi-bin/new/add_msgb?g_tk=990423949', method:'POST', headers:{ 'Accept':'text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,*/*;q=0.8', 'Accept-Encoding':'gzip, deflate', 'Accept-Language':'zh-CN,zh;q=0.8', 'Cache-Control':'max-age=0', 'Connection':'keep-alive', 'Content-Length':'套接字长度', 'Content-Type':'application/x-www-form-urlencoded', 'Cookie':'post一次获取的cookie',// 修改项 'Host':'h5.qzone.qq.com', 'Origin':'http://qzs.qq.com', 'Referer':'http://qzs.qq.com/qzone/msgboard/msgbcanvas.html', 'Upgrade-Insecure-Requests':'1', 'User-Agent':'Mozilla/5.0 (Windows NT 6.1; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/54.0.2840.87 Safari/537.36' } } var massageContent=['我','是','一','个','小','程','序'];
var i=0; setInterval(function(){ postDataObj['content']=massageContent[Math.floor(Math.random()*(massageContent.length))]; var postData=querystring.stringify(postDataObj); options['headers']['Content-Length']=postData.length; //功能:修改套接字长度 var req=http.request(options,function(res){ console.log('status: '+res.statusCode); res.on('data',function(chunk){ }) res.on('end',function(){ console.log('评论成功!No.'+(++i)); }) }) req.on('error',function(e){ console.log('Error: '+e.message); }) req.write(postData); req.end(); },10000);