一个朋友写的新浪灌水机一部

//灌水开始了 using System; using System.IO; using System.Net; using System.Collections.Specialized; using System.Text; namespace sina1 { /// /// Summary description for Class1. /// class Class1 { /// /// The main entry point for the application. /// [STAThread] static void Main(string[] args) { // test3(); // return; // // test1(); // return; WebClient clubIndexRequest = new WebClient(); clubIndexRequest.Headers.Add("User-Agent", "Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1; .NET CLR 1.1.4322)"); clubIndexRequest.Headers.Add("Accept", "*/*)"); Stream stream = clubIndexRequest.OpenRead("http://house.sina.com.cn/allclub/index.html"); StreamReader reader = new StreamReader(stream); String clubIndexResponse = reader.ReadToEnd(); String url = "href=http://comment.sina.com.cn/cgi-bin/comment/comment.cgi"; int pos1 = 0; int pos2 = 0; String userName = System.Web.HttpUtility.UrlEncode("抗议松下热水器", Encoding.GetEncoding("GB2312")); string rawContent = "恐怖的松_下热水器\r\n我本来不想买小_日本的东西的,但是老婆做主,买了 一个松_下的燃气热水器,花了1千8百多大洋\r\n没想到安装的时候还收了我522元,522元啊!\r\n今天 打投诉电话,居然说还有收8百多的!\r\n各位业主,买松_下热水器的时候小心啊,说不定象我这样当了 冤大头。\r\n我可以提供证据。"; String content = System.Web.HttpUtility.UrlEncode(rawContent, Encoding.GetEncoding ("GB2312")); while((pos1 = clubIndexResponse.IndexOf(url, pos2)) >= 0) { // 分析业主论坛 pos1 += url.Length + 1; pos2 = clubIndexResponse.IndexOf(" ", pos1); String clubStr = clubIndexResponse.Substring(pos1, pos2 - pos1); // 预提交(新浪的防灌水措施) // 创建post数据 String postStr = clubStr; postStr = postStr + "&top_title="; postStr = postStr + "&top_url="; postStr = postStr + "&user=" + userName; postStr = postStr + "&password=" + password; postStr = postStr + "&content=" + content; postStr = postStr + "&temp_content=" + content; byte [] postData = Encoding.ASCII.GetBytes(postStr); WebClient command = new WebClient(); command.Headers.Add("Content-Type", "application/x-www-form-urlencoded"); command.Headers.Add("User-Agent", "Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1; .NET CLR 1.1.4322)"); command.Headers.Add("Accept", "*/*)"); try { byte [] returnData = command.UploadData("http://comment.sina.com.cn/cgi- bin/comment/comment_do.cgi", "POST", postData); String cookie = command.ResponseHeaders["Set-Cookie"]; String returnStr = Encoding.GetEncoding("GB2312").GetString(returnData); // 再分析,再提交(新浪的防灌水措施) String timeTagIndex = "", pos3); String timeTag = returnStr.Substring(pos3, pos4 - pos3); String datetimeIndex = "", pos3); String dateTime = returnStr.Substring(pos3, pos4 - pos3); dateTime = System.Web.HttpUtility.UrlEncode(dateTime, Encoding.GetEncoding ("GB2312")); String doCommentPostStr = "hidecnt=1"; doCommentPostStr = doCommentPostStr + "&" + clubStr; doCommentPostStr = doCommentPostStr + "&page=0"; doCommentPostStr = doCommentPostStr + "&top_title="; doCommentPostStr = doCommentPostStr + "&top_url="; doCommentPostStr = doCommentPostStr + "&timetag=" + timeTag; doCommentPostStr = doCommentPostStr + "&datetime0=" + dateTime; doCommentPostStr = doCommentPostStr + "&uid0=" + userName; doCommentPostStr = doCommentPostStr + "&content0=" + content; postData = Encoding.ASCII.GetBytes(doCommentPostStr); command.Headers.Add("Content-Type", "application/x-www-form-urlencoded"); command.Headers.Add("User-Agent", "Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1; .NET CLR 1.1.4322)"); command.Headers.Add("Accept", "*/*)"); command.Headers.Add("Referer", "http://comment.sina.com.cn/cgi- bin/comment/comment_do.cgi"); command.Headers.Add("Cookie", cookie); returnData = command.UploadData("http://comment.sina.com.cn/cgi- bin/comment/comment.cgi", "POST", postData); returnStr = Encoding.GetEncoding("GB2312").GetString(returnData); System.Console.WriteLine("\r\n***************发贴成功****************"); System.Console.WriteLine(clubStr); System.Console.WriteLine("***************发贴成功****************"); } // if(pos3 >= 0) } // if(pos3 >= 0) else { System.Console.WriteLine("\r\n***************接收到错误的信息****************"); System.Console.WriteLine(returnStr); System.Console.WriteLine("***************接收到错误的信息****************"); } } catch(Exception e) { System.Console.WriteLine("\r\n***************发送异常****************"); System.Console.WriteLine(e.Message); System.Console.WriteLine("***************发贴成功****************"); } System.Threading.Thread.Sleep(10 * 1000); } } } }
posted @ 2004-08-19 15:36  Lion  阅读(3322)  评论(2编辑  收藏  举报