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

苏飞论坛

 找回密码
 马上注册

QQ登录

只需一步,快速开始

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

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

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

查看: 8488|回复: 10

[HttpHelper] webqq验证码与cookie

[复制链接]
发表于 2014-8-7 16:48:24 | 显示全部楼层 |阅读模式
1金钱
QQ五笔截图未命名.png
这图片会不会小了点?看不太清



1. 开通SVIP会员,免费下载本站所有源码,不限次数据,不限时间
2. 加官方QQ群,加官方微信群获取更多资源和帮助
3. 找站长苏飞做网站、商城、CRM、小程序、App、爬虫相关、项目外包等点这里
 楼主| 发表于 2014-8-7 16:50:08 | 显示全部楼层
[C#] 纯文本查看 复制代码
public Image checkVerify(string qq, out string outCookies)
        {
            Image codeImage = null;
            string url = "http://check.ptlogin2.qq.com/check?uin=" + qq + "&appid=1003903&r=0.5058025715431";

            #region httphelper
            HttpHelper httphelper = new HttpHelper();
            HttpItem httpitem = new HttpItem()
            {
                Referer = "http://d.web2.qq.com/proxy.html?v=20110331002&callback=1&id=2",
                UserAgent = "Mozilla/4.0 (compatible; MSIE 7.0; Windows NT 5.1; Trident/4.0; .NET CLR 2.0.50727; .NET CLR 3.0.04506.30; .NET CLR 3.0.4506.2152; .NET CLR 3.5.30729; .NET CLR 1.1.4322; .NET4.0C; .NET4.0E)",
                Accept = "*/*",
                ContentType = "application/x-www-form-urlencoded; charset=UTF-8",
                Encoding = Encoding.UTF8,
                URL = url
            };
            HttpResult httpresult = httphelper.GetHtml(httpitem);
            string result = httpresult.Html;
            outCookies = httpresult.Cookie;
            
            //CookieContainer cookiecontainer = new CookieContainer();
            //_HttpHelper.GetHtml(url, cookiecontainer);
            #endregion
            
            //string result = getHtml(url, "get", null);
            hex16 = Utils.gethex(result);
            if (result.IndexOf("!") < 0)
            {
                //需要验证图片
                String verifyUrl = "http://captcha.qq.com/getimage?aid=1003903&uin=" + qq + "&r=" + rd.NextDouble();
                #region 图片
                httpitem = new HttpItem()
                {
                    Referer = "http://d.web2.qq.com/proxy.html?v=20110331002&callback=1&id=2",
                    UserAgent = "Mozilla/4.0 (compatible; MSIE 7.0; Windows NT 5.1; Trident/4.0; .NET CLR 2.0.50727; .NET CLR 3.0.04506.30; .NET CLR 3.0.4506.2152; .NET CLR 3.5.30729; .NET CLR 1.1.4322; .NET4.0C; .NET4.0E)",
                    Accept = "*/*",
                    ContentType = "application/x-www-form-urlencoded; charset=UTF-8",
                    Encoding = Encoding.UTF8,
                    Cookie = outCookies,
                    URL = verifyUrl,
                    ResultType = ResultType.Byte
                };
                httpresult = httphelper.GetHtml(httpitem);
                Image img = byteArrayToImage(httpresult.ResultByte);
                
                #endregion
                
                codeImage = img;//Image.FromStream(img);
                outCookies = httpresult.Cookie;
                //pubModel.cookie = httpresult.Cookie;
            }
            else
            {
                this.verifyCode = result.Substring(result.IndexOf("!"), 4);
                this.hex16 = result.Substring(result.IndexOf("\\"), 32);
                this.hex16 = this.hex16.Replace("\\x", "");
                
            }
            pubModel.cookie = outCookies;
            ManageAccountAdd(qq, pubModel);
            //cookie = httpresult.Cookie;
            return codeImage;
        }
回复

使用道具 举报

 楼主| 发表于 2014-8-7 16:51:23 | 显示全部楼层
现在的问题是需要验证码的就能正常得到cookie,如果没有验证码得到的cookie是错误的
不知道问题出在哪里,请教各位路过的高人,指点一下
回复

使用道具 举报

发表于 2014-8-7 16:52:04 | 显示全部楼层
你打印出来看看两边的Cookie差什么,估计就能看出来什么问题
回复

使用道具 举报

 楼主| 发表于 2014-8-7 16:58:19 | 显示全部楼层
站长苏飞 发表于 2014-8-7 16:52
你打印出来看看两边的Cookie差什么,估计就能看出来什么问题

1.png
2.png
这是两个cookie的对比
回复

使用道具 举报

发表于 2014-8-7 17:09:02 | 显示全部楼层
那你使用集合形式的cookie试试,或者是把Cookie中的Path=/之类的替换为空,也可能是格式问题。
回复

使用道具 举报

发表于 2014-8-7 17:19:07 | 显示全部楼层
本帖最后由 Cheungnotes 于 2014-8-7 17:21 编辑

是不是先判断是否需要验证码? 如果是这样,需要验证码就是你输入的验证码,如果不需要会返回四个大写的字符,你把那个传递过去就好了,应该和空间的差不多!
回复

使用道具 举报

 楼主| 发表于 2014-8-7 17:23:29 | 显示全部楼层
Cheungnotes 发表于 2014-8-7 17:19
是不是先判断是否需要验证码? 如果是这样,需要验证码就是你输入的验证码,如果不需要会返回四个大写的字 ...

我有做判断的
需要输入验证码的,会在获取验证码的时候再次返回cookie
而不需要验证码的那个cookie在提交第一次登录的时候就返回了。
回复

使用道具 举报

 楼主| 发表于 2014-8-7 17:26:02 | 显示全部楼层
Cheungnotes 发表于 2014-8-7 17:19
是不是先判断是否需要验证码? 如果是这样,需要验证码就是你输入的验证码,如果不需要会返回四个大写的字 ...

[C#] 纯文本查看 复制代码
public Image checkVerify(string qq, out string outCookies)
        {
            Image codeImage = null;
            string url = "http://check.ptlogin2.qq.com/check?uin=" + qq + "&appid=1003903&r=0.5058025715431";

            #region httphelper
            HttpHelper httphelper = new HttpHelper();
            HttpItem httpitem = new HttpItem()
            {
                Referer = "http://d.web2.qq.com/proxy.html?v=20110331002&callback=1&id=2",
                UserAgent = "Mozilla/4.0 (compatible; MSIE 7.0; Windows NT 5.1; Trident/4.0; .NET CLR 2.0.50727; .NET CLR 3.0.04506.30; .NET CLR 3.0.4506.2152; .NET CLR 3.5.30729; .NET CLR 1.1.4322; .NET4.0C; .NET4.0E)",
                Accept = "*/*",
                ContentType = "application/x-www-form-urlencoded; charset=UTF-8",
                Encoding = Encoding.UTF8,
                URL = url
            };
            HttpResult httpresult = httphelper.GetHtml(httpitem);
            string result = httpresult.Html;
            outCookies = httpresult.Cookie;
            
            //CookieContainer cookiecontainer = new CookieContainer();
            //_HttpHelper.GetHtml(url, cookiecontainer);
            #endregion
            
            //string result = getHtml(url, "get", null);
            hex16 = Utils.gethex(result);
            if (result.IndexOf("!") < 0)
            {
                //需要验证图片
                String verifyUrl = "http://captcha.qq.com/getimage?aid=1003903&uin=" + qq + "&r=" + rd.NextDouble();
                #region 图片
                httpitem = new HttpItem()
                {
                    Referer = "http://d.web2.qq.com/proxy.html?v=20110331002&callback=1&id=2",
                    UserAgent = "Mozilla/4.0 (compatible; MSIE 7.0; Windows NT 5.1; Trident/4.0; .NET CLR 2.0.50727; .NET CLR 3.0.04506.30; .NET CLR 3.0.4506.2152; .NET CLR 3.5.30729; .NET CLR 1.1.4322; .NET4.0C; .NET4.0E)",
                    Accept = "*/*",
                    ContentType = "application/x-www-form-urlencoded; charset=UTF-8",
                    Encoding = Encoding.UTF8,
                    Cookie = outCookies,
                    URL = verifyUrl,
                    ResultType = ResultType.Byte
                };
                httpresult = httphelper.GetHtml(httpitem);
                Image img = byteArrayToImage(httpresult.ResultByte);
                
                #endregion
                
                codeImage = img;//Image.FromStream(img);
                outCookies = httpresult.Cookie;
                //pubModel.cookie = httpresult.Cookie;
            }
            else
            {
                this.verifyCode = result.Substring(result.IndexOf("!"), 4);
                this.hex16 = result.Substring(result.IndexOf("\\"), 32);
                this.hex16 = this.hex16.Replace("\\x", "");
                
            }
            pubModel.cookie = outCookies;
            ManageAccountAdd(qq, pubModel);
            //cookie = httpresult.Cookie;
            return codeImage;
        }

这是我写的代码,给看看有没有问题
回复

使用道具 举报

发表于 2014-8-7 17:35:04 | 显示全部楼层
1.png
这个不需要验证码  返回四个字符  登陆加密的时候就传这个值

2.png

这个是要验证码的 qq的都要先进行这样的判断的
回复

使用道具 举报

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

本版积分规则

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

GMT+8, 2024-5-18 08:18

© 2014-2021

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