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

苏飞论坛

 找回密码
 马上注册

QQ登录

只需一步,快速开始

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

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

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

查看: 5500|回复: 2

[求助] cookie取不到,求教

[复制链接]
发表于 2015-5-19 04:50:40 | 显示全部楼层 |阅读模式
163邮件的自动登陆,登陆的成功,但是登陆后他有一个跳转,登陆能够成功,但是获取cookie总是不对,下一步读取邮件内容就会出错.

1.邮箱首页
1V_S~]}3PKRMZYM}[6L}AK5.png
通过对页面请求的抓取,可以看到登陆是类似
https://mail.163.com/entry/cgi/n ... _34_660_bj&uid=邮箱地址   post请求
postdata是如下内容:
"savelogin=0&url2=http%3A%2F%2Fmail.163.com%2Ferrorpage%2Ferror163.htm&username=用户名&password=密码
QQ截图20150519042232.png
[C#] 纯文本查看 复制代码
string html = string.Empty;
            HttpHelper http = new HttpHelper();
            HttpItem item2 = new HttpItem();
            //邮箱登陆url
            string Urlstr="https://mail.163.com/entry/cgi/ntesdoor?"
                +"df=mail163_letter"
                +"&from=web"
                +"&funcid=loginone"
                +"&iframe=1"
                +"&language=-1"
                +"&passtype=1"
                +"&product=mail163"
                +"&net=c"
                +"&style=-1"
                +"&race=-2_23_-2_hz"
                +"&uid="+ user ; 
            HttpItem item = new HttpItem()
            {
                //savelogin=0&url2=http%3A%2F%2Fmail.163.com%2Ferrorpage%2Ferror163.htm&username=bearstand2015&password=76411lH123
                

                URL =Urlstr,   //URL     必需项    
                Method = "post",//URL     可选项 默认为Get   
                Referer = "http://mail.163.com/",//来源URL     可选项   
                Postdata = string.Format("savelogin=0&url2={0}&username={1}&password={2}", URLEncode(_erroLoginUrl), user,pwd),
                ContentType = "application/x-www-form-urlencoded",//返回类型    可选项有默认值  
                Allowautoredirect=true,
                AutoRedirectCookie =true,
                ResultCookieType = ResultCookieType.CookieCollection
            };

            HttpResult result = http.GetHtml(item);
            CookieCollection cookie = result.CookieCollection;


这一步成功通过,能够看到,登陆成功
返回一个跳装的链接
QQ截图20150519043315.png

这个页面才是真正的登陆后页面,关键正确的cookie在这里
对这个页面我做get,页面能够获取
[C#] 纯文本查看 复制代码
  
            //提取登陆后邮箱地址
            Regex Rgx = new Regex(@"(?<=href = "")(.+?)(?="")", RegexOptions.IgnoreCase);
            MatchCollection mc = Rgx.Matches(result.Html);
            string LoginedUrl = string.Empty;
            foreach (Match m in mc)
            {
                LoginedUrl = m.Value.Trim();
            }

            //http://mail.163.com/js6/read/readhtml.jsp?mid=41:1tbiKQ-9fFEAOuTFoAABsM&font=15&color=064977
        //http://mail.163.com/entry/cgi/ntesdoor?df=loginjustnowmail163&funcid=loginjustnow&iframe=1
            //进入邮箱主界面
           // string Sid = HttpHelper.GetBetweenHtml(LoginedUrl,"sid=","&");
            item = new HttpItem()
           {
               //URL = "http://mail.163.com/",//URL     必需项  
               URL = LoginedUrl,
               Accept="image/gif, image/jpeg, image/pjpeg, application/x-ms-application, application/vnd.ms-xpsdocument, application/xaml+xml, application/x-ms-xbap, */*",
               UserAgent ="Mozilla/4.0 (compatible; MSIE 7.0; Windows NT 6.0; Trident/5.0; SLCC1; .NET CLR 2.0.50727; .NET CLR 3.5.30729; .NET CLR 3.0.30729; .NET4.0C; .NET4.0E)",
               Host  = "mail.163.com",             
               ResultCookieType = ResultCookieType.CookieCollection
           };
            result = http.GetHtml(item);
            cookie = result.CookieCollection;

QQ截图20150519044536.png
这里的cookie没取到,不知道什么情况.
可是我用开发助手却能取到,我不明白问题在哪,麻烦大家指点一下.
QQ截图20150519044823.png
助手自动提取的cookie是正确的,在登陆的过程中,也能看到cookie的变化.



1. 开通SVIP会员,免费下载本站所有源码,不限次数据,不限时间
2. 加官方QQ群,加官方微信群获取更多资源和帮助
3. 找站长苏飞做网站、商城、CRM、小程序、App、爬虫相关、项目外包等点这里
发表于 2015-5-19 08:18:10 | 显示全部楼层
开发助手是通过控件提取的
发表于 2015-5-19 22:11:02 | 显示全部楼层
问题还是没说清!用啥控件?不用控件行不?
您需要登录后才可以回帖 登录 | 马上注册

本版积分规则

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

GMT+8, 2024-5-9 00:59

© 2014-2021

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