http://www.sufeinet.com/plugin.php?id=keke_group

苏飞论坛

 找回密码
 马上注册

QQ登录

只需一步,快速开始

分布式系统框架(V2.0) 轻松承载百亿数据,千万流量!讨论专区 - 源码下载 - 官方教程

HttpHelper爬虫框架(V2.7-含.netcore) HttpHelper官方出品,爬虫框架讨论区 - 源码下载 - 在线测试和代码生成

HttpHelper爬虫类(V2.0) 开源的爬虫类,支持多种模式和属性 源码 - 代码生成器 - 讨论区 - 教程- 例子

查看: 4881|回复: 8

[咨询站长] 验证码get回来不一致

[复制链接]
发表于 2015-4-9 09:20:02 | 显示全部楼层 |阅读模式
1金钱
我点击刷新验证码  get回来的居然不一样,请问这种验证码怎么获取才能和服务器存储的一致,请求站长帮忙 谢谢 QQ图片20150409091623.png

12

12


1. 开通SVIP会员,免费下载本站所有源码,不限次数据,不限时间
2. 加官方QQ群,加官方微信群获取更多资源和帮助
3. 找站长苏飞做网站、商城、CRM、小程序、App、爬虫相关、项目外包等点这里
发表于 2015-4-9 09:34:51 | 显示全部楼层
带上Cookie
回复

使用道具 举报

 楼主| 发表于 2015-4-9 09:38:08 | 显示全部楼层

能说清楚点吗,为什么监听到的 跟实际显示出来的不一样 ,这个过程跟我们模拟是一致的,带上的cookie 就算对的 你post过去的验证码不是服务器那边的验证码,
回复

使用道具 举报

发表于 2015-4-9 10:19:15 | 显示全部楼层
一样不一样,没有影响吧。只要带好Cookie,能成功提取就行
回复

使用道具 举报

 楼主| 发表于 2015-4-9 15:20:48 | 显示全部楼层
站长苏飞 发表于 2015-4-9 10:19
一样不一样,没有影响吧。只要带好Cookie,能成功提取就行

cookie也带了并且 值也跟监听到的一样,真不知道提交老是错误 。站长能分析其原因不,十分感谢了!
回复

使用道具 举报

发表于 2015-4-9 15:24:47 | 显示全部楼层
看一下是登录页面返回的Cookie还是,验证码页面,别能错了。
回复

使用道具 举报

 楼主| 发表于 2015-4-9 15:51:15 | 显示全部楼层
站长苏飞 发表于 2015-4-9 15:24
看一下是登录页面返回的Cookie还是,验证码页面,别能错了。

登录页面和验证码地址都试过了 都能返回cookie 但都提交验证码错误 快奔溃了。
回复

使用道具 举报

发表于 2015-4-9 15:55:45 | 显示全部楼层
发下包和代码看看 安说不应该的
回复

使用道具 举报

 楼主| 发表于 2015-4-9 16:05:00 | 显示全部楼层
站长苏飞 发表于 2015-4-9 15:55
发下包和代码看看 安说不应该的

登录页面产生的cookie: 2.png
验证码页面: 3.png

实现代码:
//第一种获取登陆页面cookie用于获取验证码和post业务
                        //string fristUrl = "http://www.plateno.com/login.html?from=sso";
                        //HttpItem fristItem = new HttpItem
                        //{
                        //    URL = fristUrl,
                        //    Referer = fristUrl,
                        //    ResultCookieType = ResultCookieType.CookieCollection,
                        //    ResultType = ResultType.String
                        //};
                        //HttpResult fristResult = _HttpHelper.GetHtml(fristItem);
                        //fristCookieCollection = fristResult.CookieCollection;
                        //logCookie = fristResult.Cookie;


                        //第二步Get 携带第一次的cookie请求验证码
                        if (!string.IsNullOrEmpty(imgUrl))
                        {

                            string ImgUrl = imgUrl + "&r=" + DateTime.Now.Ticks.ToString();
                            string ImgPath = AppDomain.CurrentDomain.BaseDirectory + "/validateImg.jpg";
                            HttpItem httpImgItem = new HttpItem
                            {
                                KeepAlive = true,
                                URL = ImgUrl,
                                ResultType = ResultType.Byte,
                                Referer = ImgUrl,
                                ResultCookieType = ResultCookieType.CookieCollection

                            };

                            HttpResult imgResult = _HttpHelper.GetHtml(httpImgItem);
                            byte[] bytes = imgResult.ResultByte;
                            File.WriteAllBytes(ImgPath, bytes);
                            cookieImgCollection = imgResult.CookieCollection;
                            cookieImgStr = imgResult.Cookie;
                            imgCode = DCHelper.GetImgValidateCode(ImgPath, Application.AppOperations.SystemArgs.SysArgs.ImgValidateAccountInfo.Rows[0]["Account"].ToString(), Application.AppOperations.SystemArgs.SysArgs.ImgValidateAccountInfo.Rows[0]["Pwd"].ToString());
                        }

                        //第三步登陆
                        Dictionary<string, string> reqDic = DataRowToDic(row);
                        reqDic[bDt.Columns[bDt.Columns.Count - 1].ColumnName] = imgCode;
                        Dictionary<string, string> dic = new Dictionary<string, string>();
                        dic.Add("fromType", "0");
                        dic.Add("username", "18802030513");
                        dic.Add("password", "kpe");
                        dic.Add("lgCheckcode", imgCode);
                       // dic.Add("atk", "2c7e59fae0c7416ea435ac3ecb682111");
                       // dic.Add("j_expiredays", "0");
                       // dic.Add("passwordType", "0");

                        //第三步发送POST请求
                        HttpItem item = new HttpItem
                        {
                            Referer = loginUrl,
                            URL = loginUrl,
                            Method = "Post",
                            PostEncoding = Encoding.UTF8,
                            ContentType = "application/x-www-form-urlencoded",
                            PostDic = dic,
                            ResultCookieType = ResultCookieType.CookieCollection,
                            Cookie = cookieImgStr
                        };

                        HttpResult httpResult= _HttpHelper.GetHtml(item);
                        resul = httpResult.Html;
                        object pr1 = JsonTools.JsonToObject(resul, new RegResultInfo());
                        RegResultInfo res1 = (RegResultInfo)pr1;
                        if (res1.result == "1")
                        {
                            CompleteSql = string.Format(CompleteSql, 1, resul, row["id"].ToString());
                        }
                        else
                            CompleteSql = string.Format(CompleteSql, 0, resul, row["id"].ToString());

回复

使用道具 举报

您需要登录后才可以回帖 登录 | 马上注册

本版积分规则

QQ|手机版|小黑屋|手机版|联系我们|关于我们|广告合作|苏飞论坛 ( 豫ICP备18043678号-2)

GMT+8, 2024-5-16 23:39

© 2014-2021

快速回复 返回顶部 返回列表