예제 #1
0
        private string[] downloadOne(CsdnResouce cdrs)
        {
            string[] status = { "模拟下载", "成功/失败", "无验证码", "状态信息", "无附加信息" };
            //if (code != "")
            //{
            //    status[3] = "验证码:" + code;
            //}
            status[0] = "模拟下载";
            status[1] = "";
            status[2] = "";
            status[3] = "";
            status[4] = "";
            //Logscomsole(status);
            string url = cdrs.Tag.ToString().Replace("detail", "download");
            string res = new HttpHelpers().GetHtml(new HttpItems()
            {
                URL = url ,
                Container = cc
            }).Html;

            string taskName = "";
            string regexCode = "<meta name=\"description\" content=\"(.*?)\" />";
            Regex reg = new Regex(regexCode);
            taskName = reg.Match(res).Groups[1].Value;
            regexCode = "action=\"(http://download.csdn.net/index.php/source/do_download/(.*?))\"";
            reg = new Regex(regexCode);
            if (reg.IsMatch(res))
            {
                string durl = reg.Match(res).Groups[1].Value;
                // cdrs .Durl = durl;//下载地址
                bool first = true;
                hr_down = new HttpHelpers().GetHtml(new HttpItems()
                {
                    URL = durl,
                    Referer = url,
                    Method = "Post",
                    Container = cc,
                    Allowautoredirect = true,
                    Postdata = "ds=&validate_code=&basic%5Breal_name%5D=&basic%5Bmobile%5D=&basic%5Bemail%5D=&basic%5Bjob%5D=&basic%5Bcompany%5D=&basic%5Bprovince%5D=&basic%5Bcity%5D=&basic%5Bindustry%5D="
                });
                res = hr_down.Html;
            TRUEDOWNLOAD:
                if (res.Contains("您因违反"))
                {
                    status[0] = "模拟下载";
                    status[1] = "失败";
                    status[2] = res ;
                    status[3] = "";
                    status[4] = "";
                    Logscomsole(status );
                    this.Clear();
                    return status;
                }
                if (res != "<script>document.domain='csdn.net';parent.show_validate_pop();</script>")
                {           //模拟点击下载
                    if (saveFile && !string.IsNullOrEmpty(savePath))
                    {

                        if (!Directory.Exists(SavePath))
                        {
                            Directory.CreateDirectory(SavePath);
                        }
                        //href='http://dldx.csdn.net/fd.php?i=391492108198497&s=c936639a4ad2171ef2bee9ae9e706700';

                        try
                        {
                            hr_down = new HttpHelpers().GetHtml(new HttpItems()
                            {
                                URL = res.Substring(res.IndexOf("http"), res.LastIndexOf('\'') - res.IndexOf("http")),
                                Referer = durl,
                                Container = cc,
                                ResultType = ResultType.Byte,
                                Allowautoredirect = true
                            });
                            //hr.ResultByte;  真实文件内容
                            byte[] bty = hr_down.ResultByte;
                            string a = hr_down.Header.Get("Content-Disposition");
                            a = a.Substring(a.LastIndexOf('\'') + 1);
                            a = HttpUtility.UrlDecode(a, Encoding.UTF8);
                            //a = Encoding.Default.GetString(Encoding.UTF8.GetBytes (a));
                            //a = Encoding.UTF8.GetString(Encoding .UTF8 .GetBytes (a) );
                            cdrs.Log = a;
                            cdrs.Msg = "已保存";
                            File.WriteAllBytes(SavePath + @"\" + a, bty);
                        }
                        catch (Exception ex)
                        {

                            cdrs.Msg = "保存失败:" + ex.Message;
                        }

                    }
                    status[0] = "模拟下载";
                    status[1] = "成功";
                    status[3] = string.IsNullOrEmpty (cdrs.Name )?"":cdrs .Name ;
                    status[2] = first ?"无验证码":"已智能识别验证码";
                    status[4] = "";
                    //cdrs.Rel = "成功";
                    //cdrs.Msg = res==""?"":"验证码:"+res ;
                    //Logscomsole("", "", "", cdrs);
                    return status ;
                }
                else
                {
                    if (first && getImgVcode != null)
                    {
                        res = getdownVcodeUrl(durl, url);
                        first = false;
                        goto TRUEDOWNLOAD;
                    }
                    status[0] = "模拟下载";
                    status[1] = "失败";
                    status[2] = "多次识别错误或者验证码识别接口出错";
                    status[3] = "";
                    status[4] = "";
                }

            }
            else
            {
                status[0] = "模拟下载";
                status[1] = "失败";
                status[2] = "获取下载地址失败";
                status[3] = "";
                status[4] = "";
                //Logscomsole(status);
                //cdrs.Rel = "失败";
                //cdrs.Msg = "获取下载抵制失败";
            }

            //Logscomsole("", "", "", cdrs);
            return status ;
        }
예제 #2
0
        private string[] commandOne(CsdnResouce item, string code = "")
        {
            string[] status = { "模拟评分", "成功/失败", "无验证码", "状态信息", "无附加信息" };
            if (code != "")
            {
                status[2] = "验证码:"+code ;
            }
            hr_com = new HttpHelpers().GetHtml(new HttpItems() {
                URL = "http://download.csdn.net/index.php/comment/get_comment_data/" + item.Id + @"/1?jsonpcallback=jsonp1448000002880&&t=1448000436379",
                Container = cc,
                Referer = item.Url
            } );

            string rehtml = hr_com.Html.Replace("\\r\\n", "").Replace("\\n", "").Replace("\\t", "").Replace(" ", "");
            rehtml = Decode(rehtml);
            Regex regcont=new Regex (@"user_name\\"">(.*?)<\\\/a><\\\/dt><dd>(.*?)<");
            MatchCollection mccont = regcont.Matches(rehtml);
            rehtml = "";
            foreach (Match  m in mccont )
            {
                if (rehtml.Length < m.Groups[2].Value.Length)
                {
                    rehtml = m.Groups[2].Value;
                }
            }
            //getCommandList();
            long epochS = (DateTime.Now.AddSeconds(-5).ToUniversalTime().Ticks - 621355968000000000) / 10000;
            long epochE = (DateTime.Now.ToUniversalTime().Ticks - 621355968000000000) / 10000;
            //Get评论
            int index = ran.Next(comMsg.Length);
            string commentcon=comMsg [index ]+","+rehtml ;
            string url;

            if ("".Equals(code))
            {
                url = string.Format("http://download.csdn.net/index.php/comment/post_comment?jsonpcallback=jsonp{0}&sourceid={1}&content={2}&rating={3}&t={4}", epochS, item.Id, new XJHTTP().UrlEncoding(item.Name + commentcon ), new Random().Next(3, 6), epochE);
            }
            else
            {
                url = string.Format("http://download.csdn.net/index.php/comment/post_comment?jsonpcallback=jsonp{0}&sourceid={1}&content={2}&txt_validcode={3}&rating={4}&t={5}", epochS, item.Id, new XJHTTP().UrlEncoding(item.Name + commentcon), code, new Random().Next(3, 6), epochE);
            }

            string html = new HttpHelpers().GetHtml(new HttpItems() {
                URL =url ,
                Container =cc
            }).Html;

            //评论成功完成
            if (html.Contains("\"succ\":1"))
            {
                JfCount++;
                status[1] = "成功";
                status[3] = "当前积分:" + JfCount.ToString();
                status[4] = item.Name + comMsg[index];
            }
            else
            {
                status[1] = "失败";
                status[3] = "当前积分:" + JfCount.ToString();

                Regex reg = new Regex("msg\":\"(.+?)\"");
                string msg = new XJHTTP().FromUnicodeString(html);
                MatchCollection mc = reg.Matches(msg);
                if (mc.Count > 0)
                {
                    status[4] = mc[0].Groups[1].Value;
                    //item.Msg = mc[0].Groups[1].Value;
                }
                else
                {
                    status[4] = msg;
                    //item.Msg = msg;
                }

                if ((status[4].Contains("请填写验证码") || status[4].Contains("验证码错误")) && getImgVcode != null)
                {
                    string vcode = getcomVcode("http://download.csdn.net/index.php");
                    if (vcode != "")
                    {
                        return commandOne(item, vcode);
                    }
                }
                else if(msg .Contains ("您因违反"))
                {
                    status[4] = msg;
                    Logscomsole(status );
                    this.Clear();
                    return status;
                }

            }
            return status;
        }