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

苏飞论坛

 找回密码
 马上注册

QQ登录

只需一步,快速开始

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

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

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

查看: 19264|回复: 1

[例子] 关于淘宝模拟登录的讨论

[复制链接]
发表于 2014-8-9 18:06:50 | 显示全部楼层 |阅读模式
    首先感谢下【1602264241】这位兄弟的帖子【http://www.sufeinet.com/thread-4585-1-1.html】.
    兄的业务和我基本一致,我是需要进入量子,然后使用量子不对外开放的API【不登录就不能通过API来查询数据】,来获取数据。
    业务很简单,但是有2个问题。
    1.验证码
       虽然做个do  while循环,有很大的概率登录跳过验证码进行登录(基本上循环次数都是在10次以下,但是有些还时候,验证了几百次也不能登录成功,我做的是后台定时作业,所以肯定没人输入验证码,所以就用这种方式)。
       但是毕竟失败几率也是比较高的,另外在心里总是一个结,想要解开。
        在返回的数据中的data的ccurl获取到图片链接后,把图片显示出来,输入验证码然后再次登录
        发现一个问题,我们重新post的时候,是另外一个session,而这个session和图片链接的不一样。所以就每次都提示错误
       然后想先调用https://login.taobao.com/member/ ... input_charset=utf-8  传入用户名检查是否图片验证,结果每次的结果都是false。就没办法先获取图片,然后再输入验证码。
        哪位朋友有解决方案,大家可以参考下。
     2.跳转淘宝
       我们已经可以模拟登录淘宝了,也就是说可以进入淘宝系统了,如果从当前的页面redirect到淘宝的页面,携带当前的信息跳转过去。


[C#] 纯文本查看 复制代码
  HttpItem item ;
            string html="";
            HttpResult result;
            Msg1 s = new Msg1();
            #endregion

            #region 淘宝登录3步-第1步
            do
            {
                //if (s.message == "为了您的账户安全,请输入验证码。" || s.message == "验证码错误,请重新输入。")
                //{
                //    Response.Write("<script>window.showModelDialog('WebForm2.aspx')</script>");
                //}

                item = new HttpItem()
                {
                    URL = "https://login.taobao.com/member/login.jhtml",
                    Method ="post",
                    Postdata =string.Format("ua=061tpOWUuXBidH1MRWQZ0InIldyJ0J3AibxJg%3D%3D%7CtaBkcTQxVCE0cTQBBIGUwRY%3D%7CtJFV4sZQBo%2BGTrafx%2B7KDiq%2Fm197DJR8NMy1jKh%2FqA%3D%3D%7Cs6aDR2N2MzZTJjN2MwYDhpPGY2aCh9Knktfy10InoveS52IXkhcz5A%3D%3D%7Csqcy9kF0sKWQVEEEwORdFD2kHYXtacHEcysChqJ1og%3D%3D%7CsTTw1PAn%7CsCXhxeE2%7Cv6q%2Fe8zoYClgaVD1AfU9xb0lzSlgeICosEislGy0QJjAGDBoQbV9hf1ljWnBSQDYEOUSimJrMnuMtDwkDTRsJfCp4Ihc2b3V%2FATcCcFoIClNdD2kbDThOaFJ0ehwqKFpMVWNFf1lbHRdRZCVUVSQlfHYgMhQeSEZUKf%2B1x%2FKQgtCSx86b1pMGD1oTSt%2FWg8qTIQtyYCYYEhQqEx0jFQAJXBVM%2FsDe%2BMLX3ovCmw4HUh9G39WvvYjNnN2E2ZzNnNWE4bj5oK74sofVn8mflqeup5Jng%3D%3D%7CvotP%2BN34rWnsyewoHQiNSWzpvHhtWC1IjPmMyQ0YLVg9%2BYzJnEuc%7CvaidWe7KvSXNhX0EPTlMaKyI%2F2mPi57bHxre2x8KTxo%2B6T4%3D%7CvKmsaEz7rpuOG26qbUlcGRx5DAmMidy5%2FIm8dXCUgbQhVMFUUTQRJDEUURQRZBHW8jYj9NAH%7Cu94arYkv2O%2F3n8ef108GE1ZTNkNWE1ZzJhNWAyfj9sMHAsbzpsPWAdY%3D%7Cuv%2F6%2Fzs%2B%2Bt8bDktemq%2F6j0sei086b6u%2Bq%2B4qP%2Fvui45K39oeO265&TPL_username=%E4%B8%83%E6%A0%BC%E6%A0%BC%E5%90%89%E7%A5%A5&TPL_password=3DES_2_000000000000000000000000000000_1D368DC6E81FE1E70809A8B69D65F085&TPL_username={0}&TPL_password={1}&TPL_checkcode={2}&loginsite=0&newlogin=1&TPL_redirect_url=http%3A%2F%2Flz.taobao.com%2Flogin%2F%3F&from=lzdp&fc=default&style=minisimple&css_style=&tid=XOR_1_000000000000000000000000000000_63583322450974020A07040D&support=000001&CtrlVersion=1%2C0%2C0%2C7&loginType=4&minititle=&minipara=0%2C0%2C0&umto=NaN&pstrong=&llnick=&sign=&need_sign=&isIgnore=&full_redirect=&popid=&callback=1&guf=&#172;_duplite_str=&need_user_id=&poy=&gvfdcname=10&gvfdcre=687474703A2F2F6C7A2E74616F62616F2E636F6D2F6C6F67696E2F3F7374617475733D30&from_encoding=&sub=true&allp=&oslanguage=&sr=1376*774&osVer=windows%7C6.1&naviVer=ie%7C9", HttpUtility.UrlEncode(UserName), HttpUtility.UrlEncode(UserPwd), CheckCode),
                    ContentType = "application/x-www-form-urlencoded; charset=UTF-8",
                    Allowautoredirect =true,
                   ResultCookieType =ResultCookieType.CookieCollection 
                    
                };

                result = m_Http.GetHtml(item);
                cc = result.CookieCollection;
                html = result.Html;
                s = JsonConvert.DeserializeObject<Msg1>(html);
            }
            while (s.state == "False");
            #endregion

            if (s.data.token == null) return;

            #region 淘宝登录3步-第2步
            string token = s.data.token;
            item = new HttpItem()
            {
                URL = string.Format("https://passport.alipay.com/mini_apply_st.js?site=0&token={0}&callback=vstCallback77", token),
                Accept = "application/javascript, */*;q=0.8",
                ResultCookieType =ResultCookieType.CookieCollection,
                CookieCollection = cc//result.CookieCollection
                //Cookie=cookies
            };
            result = m_Http.GetHtml(item);
            //cookies += result.Cookie;
            for (int i = 0; i < result.CookieCollection.Count; i++)
            {
                cc.Add(result.CookieCollection[i]);
            }
            html = result.Html;
            #endregion

            Match st = Regex.Match(html, "(?<=\"st\":\").*?(?=\")");
            if (st.Success == false) return;

            #region 淘宝登录3步-第3步
            item = new HttpItem()
            {
                URL = string.Format("https://login.taobao.com/member/vst.htm?st={0}&#182;ms=style%3Dminisimple%26sub%3Dtrue%26TPL_username%3D{1}%26loginsite%3D0%26from_encoding%3D%26not_duplite_str%3D%26guf%3D%26full_redirect%3D%26isIgnore%3D%26need_sign%3D%26sign%3D%26from%3Dlzdp%26TPL_redirect_url%3Dhttp%25253A%25252F%25252Flz.taobao.com%25252Flogin%25252F%25253F%26css_style%3D%26allp%3D&_ksTS=1406714434649_90&callback=jsonp91", st.Value, HttpUtility.UrlEncode("七格格吉祥")),
                Accept = "text/javascript, application/javascript, application/ecmascript, application/x-ecmascript, */*; q=0.01",
                ResultCookieType =ResultCookieType.CookieCollection ,
                CookieCollection = cc//result.CookieCollection
                //Cookie=cookies 
            };
            result = m_Http.GetHtml(item);

            for (int i = 0; i < result.CookieCollection.Count; i++)
            {
                cc.Add(result.CookieCollection[i]);
            }
            //cookies += result.Cookie;
            html = result.Html;
            #endregion

            Match url = Regex.Match(html, "(?<=\"url\":\").*?(?=\")");
            if (url.Success == false) return;

                #region 跳转量子2步
                item = new HttpItem()
                {
                    URL = url.Value,
                    Accept = "text/html, application/xhtml+xml, */*",
                    ResultCookieType =ResultCookieType.CookieCollection ,
                    CookieCollection = cc//result.CookieCollection
                };
                result = m_Http.GetHtml(item);//1
                html = result.Html;

                for (int i = 0; i < result.CookieCollection.Count; i++)
                {
                    cc.Add(result.CookieCollection[i]);
                }
                for (int i = 0; i < result.CookieCollection.Count; i++)
                {
                    if (result.CookieCollection[i].Name == "lzsession")
                    {
                        lzsession = HttpUtility.UrlDecode(result.CookieCollection[i].Value);
                        this.ASPxTextBox2.Text = lzsession;
                        break;
                    }
                }


                item = new HttpItem()
                {
                    URL = result.Header[HttpResponseHeader.Location],
                    Accept = "text/html, application/xhtml+xml, */*",
                    ResultCookieType = ResultCookieType.CookieCollection,
                    CookieCollection = cc//result.CookieCollection
                };
                result = m_Http.GetHtml(item);//2
                for (int i = 0; i < result.CookieCollection.Count; i++)
                {
                    cc.Add(result.CookieCollection[i]);
                }
                html = result.Html;
                for (int i = 0; i < result.CookieCollection.Count; i++)
                {
                    cc.Add(result.CookieCollection[i]);
                }
     

                #endregion

            #region 进入量子获取数据接口
            //item = new HttpItem()
            //{
            //    URL = string.Format("http://api.linezing.com/=/view/itemsell/type/status?days=2014-07-30..2014-07-30&dtype=d&_s={0}=&_c=OR.C[10000]", lzsession),
            //    Accept = "text/html, application/xhtml+xml, */*",
            //    ResultCookieType = ResultCookieType.CookieCollection,
            //    CookieCollection = cc
            //};
            //result = m_Http.GetHtml(item);
            //html = result.Html;
            //Response.Write(html);

            #endregion



1. 开通SVIP会员,免费下载本站所有源码,不限次数据,不限时间
2. 加官方QQ群,加官方微信群获取更多资源和帮助
3. 找站长苏飞做网站、商城、CRM、小程序、App、爬虫相关、项目外包等点这里
发表于 2014-8-13 16:19:26 | 显示全部楼层
受教了,学习中……
您需要登录后才可以回帖 登录 | 马上注册

本版积分规则

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

GMT+8, 2024-12-23 05:41

© 2014-2021

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