• 自动提交ISOHU工具


    工作之余,无聊了写一个isohu自动提交工具,下面谈谈编写这个小工具设计思路。

    1、通过写一个注册机注册isohu用户,注册地址:http://i.sohu.com/login/reg.do?bru=http%3A%2F%2Fi.sohu.com 。(注册选择sohu邮箱)

    2、拿到注册好的用户,假设已经注册好了N个用户, 导入到工具用户列表。

    3、准备好各种各样的文章,我这里是下载txt小说,大文章拆分成N篇小文章,然后导入工具的文章库,当作待发布文章库(发布文章时将各小文章组合成一篇待发布的文章,只要小文章的样本够大,随机组合后的重复性概率很低)。

    4、用百度关键词分析工具(网上下载)挖掘出最热门的关键词(N个),然后导入工具的关键词列表。

    5、准备好广告内容模板,用于嵌入文章(可以是推广链接)。

    通过上述步骤,就可以产生很多网络垃圾文章(一天可以发布几万篇文章),然后有引入百度热门关键词,发在isohu平台(百度权限比较高),在一定程度能引百度关注。只要百度一旦收录,就有一定的排名。在百度有了排名,一切都好办能引来不错的流量。

    好了,有了上述需求,分析之后,开始实现代码(列出关键部分代码)。

    1、 用户登录

    View Code
     1    /// <summary>
     2         /// 登陆isohu
     3         /// </summary>
     4         /// <param name="username">用户名</param>
     5         /// <param name="password">密码</param>
     6         /// <returns></returns>
     7         public CookieContainer login(string username, string password)
     8         {
     9             username = HttpUtility.UrlEncode(username);
    10             password = System.Web.Security.FormsAuthentication.HashPasswordForStoringInConfigFile(password, "MD5").ToLower();
    11             string s = DateTime.Now.ToString("yyyyMMddhhmmssffff");//时间间
    12 
    13             url = "https://passport.sohu.com/sso/login.jsp";
    14             paramdata = string.Format("userid={0}&password={1}&appid=1019&persistentcookie=1&s={1}&b=1&w=1440&pwdtype=1&v=26", username, password, s);
    15             encoding = Encoding.GetEncoding("gb2312");
    16             CookieContainer objcok = HttpPost.PostLogin(url, paramdata, encoding);
    17             return objcok;
    18 }

    登录cookie认证通用函数

    View Code
     1         /// <summary>
     2         /// 提交登陆
     3         /// </summary>
     4         /// <param name="username">用户名</param>
     5         /// <param name="password">密码</param>
     6         /// <param name="encoding">编码</param>
     7         /// <param name="responetxt">返回成功登录的页面HTML字符串</param>
     8         /// <returns>返回登录的cookies容器</returns>
     9         public static CookieContainer PostLogin(string url, string paramdata, Encoding encoding, out string responetxt)
    10         {
    11             HttpWebRequest request = null;
    12             HttpWebResponse response = null;
    13             StreamReader reader = null;
    14             CookieContainer cookies = null;
    15             byte[] buffer = null;
    16             responetxt = string.Empty;
    17 
    18             try
    19             {
    20                 request = (HttpWebRequest)WebRequest.Create(url);
    21                 request.Method = "post";
    22                 request.Accept = "text/html, application/xhtml+xml, */*";
    23                 request.ContentType = "application/x-www-form-urlencoded";
    24                 cookies = new CookieContainer();
    25                 request.CookieContainer = cookies;
    26                 buffer = encoding.GetBytes(paramdata);
    27                 request.ContentLength = buffer.Length;
    28                 request.GetRequestStream().Write(buffer, 0, buffer.Length);
    29             }
    30             catch (Exception ex)
    31             {
    32                 throw ex;
    33             }
    34             using (response = (HttpWebResponse)request.GetResponse())
    35             {
    36                 using (reader = new StreamReader(response.GetResponseStream(), encoding))
    37                 {
    38                     responetxt = reader.ReadToEnd();
    39                 }
    40             }
    41 
    42             if (reader != null)
    43             {
    44                 reader.Close();
    45                 reader = null;
    46             }
    47             if (response != null)
    48             {
    49                 response.Close();
    50                 response = null;
    51             }
    52             return cookies;
    53       

     2、发布文章

    View Code
     1  /// <summary>
     2         /// 提交文章
     3         /// </summary>
     4         /// <param name="objcok"></param>
     5         /// <param name="title"></param>
     6         /// <param name="message"></param>
     7         /// <param name="username"></param>
     8         /// <returns></returns>
     9         public bool post(CookieContainer objcok, string title, string message, string username)
    10         {
    11             //打开发布文章页面入口
    12             title = HttpUtility.UrlEncode(title);
    13             message = HttpUtility.UrlEncode(message);
    14 
    15             //发布文章
    16             url = "http://i.sohu.com/a/blog/home/entry/save.htm?_input_encode=UTF-8&_output_encode=UTF-8";
    17             paramdata = string.Format("entrytitle={0}&entrycontent={1}&keywords=&categoryId=&oper=art_ok&allowComment=0", title, message);
    18  string referUrl = "http://i.sohu.com/blog/home/entry/list.htm";
    19             responetext = HttpPost.PostData(url, paramdata, referUrl, objcok, encoding);
    20 
    21             //内容被禁止
    22             if (responetext.Contains("{\"status\":2,"))//"博文中含有不宜发表的言论,请修改后重新发布"
    23             {
    24                 stateCode = PostStatus.Sensitive;
    25                 stateMessage = "博文中含有不宜发表的言论,请修改后重新发布。";
    26                 return false;
    27             }
    28             //发送太快
    29             if (responetext.Contains("{\"status\":1,"))//"对不起,您发表的太快啦!喝杯茶休息一会吧"
    30             {
    31                 stateCode = PostStatus.Frequently;
    32                 stateMessage = "对不起,您发表的太快啦!喝杯茶休息一会吧。";
    33                 return false;
    34             }
    35 
    36             //Console.WriteLine(responetext);
    37             //判断是否发布成功
    38             if (responetext.Contains("博客发布成功"))
    39             {
    40                 //去博文列表地址
    41                 //CookieContainer cok = new CookieContainer();//这里不能换上新的cookie 对象,如果换上新的,访问不了列表
    42                 url = "http://i.sohu.com/blog/home/entry/list.htm";
    43                 referUrl = "";
    44                 paramdata = "";
    45                 responetext = HttpPost.PostData(url, paramdata, referUrl, objcok, encoding);
    46 
    47                 //发布成功后的文章地址
    48                 int index = -1;
    49                 int index2 = -1;
    50                 index = responetext.IndexOf("<h3>");//第一次出现标题的地方
    51                 if (index > -1 && responetext.Length >= 300)
    52                 {
    53                     contentUrl = responetext.Substring(index, 300);
    54                 }
    55 
    56                 index = contentUrl.IndexOf("\" target");
    57                 index2 = contentUrl.IndexOf("\"") + 1;
    58 
    59                 if (index > index2 && index2 >= 0)
    60                 {
    61                     contentUrl = contentUrl.Substring(index2, index - index2);
    62                 }
    63 
    64                 url = contentUrl;
    65                 paramdata = "";
    66                 CookieContainer cok = new CookieContainer();//新建一个cookies
    67                 responetext = HttpPost.PostData(url, paramdata, referUrl, cok, encoding);
    68 
    69                 if (responetext.IndexOf("<div class=\"blog-article-box\">") == -1)
    70                 {
    71                     stateCode = PostStatus.NotAllow;
    72                     stateMessage = "我x!" + username + "这个账号好像已经被封了!";
    73                     return false;
    74                 }
    75                 stateCode = PostStatus.Success;
    76             }
    77             return true;
    78         }

     HTTP提交通用函数

    View Code
     1  /// <summary>
     2         /// 提交数据
     3         /// </summary>
     4         /// <param name="postUrl">提交的URL不带参数</param>
     5         /// <param name="data">带数列表字符串</param>
     6         /// <param name="referUrl">来源URL可为空</param>
     7         /// <param name="cookie">cookie容器对象</param>
     8         /// <param name="encoding">编码类型</param>
     9         /// <returns>返回ResponseText字符串</returns>
    10         public static string PostData(string postUrl, string data, string referUrl, CookieContainer cookie, Encoding encoding)
    11         {
    12             HttpWebRequest request = null;
    13             HttpWebResponse response = null;
    14             StreamReader reader = null;
    15             byte[] buffer = null;
    16             string responseText = string.Empty;//返回的对象
    17 
    18             request = (HttpWebRequest)WebRequest.Create(postUrl);
    19 
    20             request.Method = "post";
    21             request.Accept = "image/jpeg, application/x-ms-application, image/gif, application/xaml+xml, image/pjpeg, application/x-ms-xbap, application/vnd.ms-excel, application/vnd.ms-powerpoint, application/msword, application/QVOD, application/QVOD, */*";
    22             request.ContentType = "application/x-www-form-urlencoded";
    23             request.UserAgent = ("Mozilla/4.0 (compatible; MSIE 8.0; Windows NT 6.1; Trident/4.0; SLCC2; .NET CLR 2.0.50727; .NET CLR 3.5.30729; .NET CLR 3.0.30729; Media Center PC 6.0; .NET4.0C; .NET4.0E)");
    24             request.KeepAlive = true;
    25 
    26             if (!string.IsNullOrEmpty(referUrl))
    27             {
    28                 request.Referer = referUrl;
    29             }
    30             request.ServicePoint.Expect100Continue = false;
    31             request.CookieContainer = cookie;
    32             buffer = encoding.GetBytes(data);
    33             request.ContentLength = buffer.Length;
    34             request.GetRequestStream().Write(buffer, 0, buffer.Length);
    35 
    36             try
    37             {
    38                 response = (HttpWebResponse)request.GetResponse();
    39             }
    40             catch (WebException ex)
    41             {
    42                 response = (HttpWebResponse)ex.Response;
    43             }
    44 
    45             using (reader = new StreamReader(response.GetResponseStream(), encoding))
    46             {
    47                 responseText = reader.ReadToEnd();
    48             }
    49             if (reader != null)
    50             {
    51                 reader.Close();
    52                 reader = null;
    53             }
    54             if (response != null)
    55             {
    56                 response.Close();
    57                 response = null;
    58             }
    59 
    60             return responseText;
    61         }

    随机组合发布文章函数

    View Code
      1      /// <summary>
      2         /// 根据关键词列表取得处理后的文章及关键词
      3         /// </summary>
      4         /// <param name="keyword"></param>
      5         private void getPostcontent(string keyword)
      6         {
      7             _artTitle = pm.ArtTtile.Replace("{关键词}", keyword); //替换标题模板中的关键词标签
      8             _artContent = pm.ArtContent.Replace("{关键词}", keyword);  //替换文章模板中的关键词标签
      9 
     10             string line = string.Empty;
     11             string tpath = string.Empty;
     12             int index = 0;//关键词插入索引位置
     13             int len = 0;//文章总长度
     14             int fileNameIndex = 0;//文件名称号
     15             int avg = 0;//数据文件内容分段
     16             int ti = 0;//记录上一次插入的位置
     17             int klen = 0;//关键词字符长度
     18             Random ran;//取得文件名称随机种子
     19             Random random;//文章内容位置随机种子
     20             StreamReader sr = null;
     21             sb.Length = 0;
     22 
     23             //根据设置的数据样本数,开始随机读取data目录下准备好的数据文本
     24             for (int k = 0; k < pm.ArtDataCount; k++)
     25             {
     26                 Wait(10);
     27                 ran = new Random(~((int)DateTime.Now.Ticks));
     28                 fileNameIndex = ran.Next(k, pm.TotalFile);//根据数据文本总数,取得一个随机文件名
     29                 tpath = string.Format("{0}data\\{1}.txt", AppDomain.CurrentDomain.BaseDirectory, fileNameIndex.ToString());
     30 
     31                 using (sr = new StreamReader(tpath, Encoding.UTF8))
     32                 {
     33                     line = sr.ReadToEnd();
     34                 }
     35                 index = 0;//索引位置
     36                 ti = -1;
     37                 klen = keyword.Length;
     38 
     39                 //向数据文本随机插入关键词
     40                 for (int m = 0; m < InsertKeyCount; m++)
     41                 {
     42                     len = line.Length;//文章总长度不断在变
     43                     avg = len / InsertKeyCount;//平均分段
     44                     random = new Random(~((int)DateTime.Now.Ticks));
     45                     ti = line.LastIndexOf(keyword, index);//记录上一次插入的位置
     46                     index = random.Next(avg * m, avg * (m + 1));//分段随机取
     47                     if (ti == index)//如果刚好是上一次插入的位置,则进一个关键词的长度位置
     48                     {
     49                         index += klen;
     50                     }
     51                     if (index < len)
     52                     {
     53                         line = line.Insert(index, keyword);// "[b]+ "[/b]"" +//插入关键词
     54                     }
     55                 }
     56                 sb.Append(line);
     57                 sb.Append("</p>");
     58             }
     59             if (sr != null)
     60             {
     61                 sr.Close();
     62                 sr = null;
     63             }
     64 
     65             _artContent = _artContent.Replace("{内容}", sb.ToString());//替换文章模板中内容标签
     66             sb.Length = 0;
     67 
     68             linkweel = string.Empty;
     69 
     70             //如果勾选链轮
     71             if (pm.Islinkweel)
     72             {
     73                 weelLen = pm.LinkweelArray.Count;
     74                 //如果锚文本记录数小于链轮数量,则直接循环锚文本记录,否则截取锚文本最后记录数
     75                 if (weelLen < pm.LinkweelCount)
     76                 {
     77                     for (int n = 0; n < weelLen; n++)
     78                     {
     79                         if (pm.LinkweelArray[n].Trim() != "")
     80                         {
     81                             linkweel += "<li>" + pm.LinkweelArray[n] + "</li>";//行总数
     82                         }
     83                     }
     84                 }
     85                 else
     86                 {
     87                     //根据链轮数量个数取得锚文本记录最后条数
     88                     //for (int n = pm.LinkweelCount; n > 0; n--)
     89                     //{
     90                     //    linkweel += "<li>" + pm.LinkweelArray[weelLen - n] + "</li>";
     91                     //}
     92                     for (int i = 1; i <= pm.LinkweelCount; i++)
     93                     {
     94                         if (pm.LinkweelArray[weelLen - i].Trim() != "")
     95                         {
     96                             linkweel += "<li>" + pm.LinkweelArray[weelLen - i] + "</li>";
     97                         }
     98                     }
     99                 }
    100             }
    101 
    102             _artContent = _artContent.Replace("{轮链文本}", linkweel);
    103         }

    贴一下这个工具的设计界面图

     

    这种做法,狂疯了一阵子,大概发了十万篇文章,之后就被限制了,估计isohu发现了很多的垃圾文章,改变了文章发布的认证和限制,目前还没有找到限制的突破口,因此目前这个程序发布不了isohu文章。

     

  • 相关阅读:
    Python_FTP通讯软件
    Python_NAT
    Python_跟随目标主机IP变换
    Python_网络攻击之端口
    spring
    Java多线程总结之线程安全队列Queue
    队列
    路径
    事务的概念
    GBK,UTF-8,和ISO8859-1之间的编码与解码
  • 原文地址:https://www.cnblogs.com/cgli/p/2355934.html
Copyright © 2020-2023  润新知