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

苏飞论坛

 找回密码
 马上注册

QQ登录

只需一步,快速开始

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

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

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

查看: 13847|回复: 13

[求助] httphelper get 小米网预约页面 失败

[复制链接]
发表于 2014-1-12 16:03:08 | 显示全部楼层 |阅读模式
本帖最后由 方家河农夫 于 2014-1-12 16:06 编辑

具体代码如下
HttpItem itemSign = new HttpItem()          //获取_sign
                {
                    URL = "https://account.xiaomi.com/pass/serviceLogin?tmp=" + DateTime.Now.ToString("yyyyMMddHHmmss"),
                };
                HttpHelper helperSign = new HttpHelper();
                HttpResult resultSign = helperSign.GetHtml(itemSign);//成功获取
                string _sign = System.Uri.EscapeDataString(Regex.Match(resultSign.Html, "(?<=sign = encodeURIComponent\\(\").*\"").Value.ToString().Replace("\"", ""));
                                xmdata.CallBack = System.Uri.EscapeDataString(Regex.Match(resultSign.Html, "(?<=callback = encodeURIComponent\\(\").*\"").Value.ToString().Replace("\"", ""));
                    xmdata.SID = System.Uri.EscapeDataString(Regex.Match(resultSign.Html, "(?<=sid = encodeURIComponent\\(\").*\"").Value.ToString().Replace("\"", ""));
                    xmdata.QS = System.Uri.EscapeDataString(Regex.Match(resultSign.Html, "(?<=qs = encodeURIComponent\\(\").*\"").Value.ToString().Replace("\"", ""));
                    xmdata.SIGN = System.Uri.EscapeDataString(Regex.Match(resultSign.Html, "(?<=sign = encodeURIComponent\\(\").*\"").Value.ToString().Replace("\"", ""));
                    xmdata.HIDDEN = System.Uri.EscapeDataString(Regex.Match(resultSign.Html, "(?<=hidden = encodeURIComponent\\(\").*\"").Value.ToString().Replace("\"", ""));
                    xmdata.FrameSrc = System.Uri.EscapeDataString(Regex.Match(resultSign.Html, "(?<=var iframeSrc = \").*\"").Value.ToString().Replace("\"", ""));
                }
                string cookies = resultSign.Cookie;
HttpItem itemLogin = new HttpItem()         //登陆Post
                {
                    Allowautoredirect = false,
                    URL = "https://account.xiaomi.com/pass/serviceLoginAuth2",
                    Method = "POST",
                    Cookie = cookies,
                    Referer = "https://account.xiaomi.com/pass/userInfo",
                    ContentType = "application/x-www-form-urlencoded",
                    Postdata = string.Format("passToken={0}&user={1}&pwd={2}&callback={3}&sid={4}&qs={5}&hidden={6}&_sign={7}", xmdata.PassToken, username, password, xmdata.CallBack, xmdata.SID, xmdata.QS, xmdata.HIDDEN, xmdata.SIGN)
                };
                HttpHelper helperLogin = new HttpHelper();
                HttpResult resultLogin = helperLogin.GetHtml(itemLogin);//成功登陆
              cookies += ";" + resultLogin.Cookie;
  itemLogin = new HttpItem()      
                        {
                            Allowautoredirect = false,
                            URL = "https://account.xiaomi.com/pass/userInfo",
                            Cookie = cookies,
                            ContentType = "application/x-www-form-urlencoded",
                       };
                        resultLogin = helperLogin.GetHtml(itemLogin);//成功到个人账户页面

//----------------------------------------------------------------以下到预约页面一直出错,求告诉帮忙解答

itemLogin = new HttpItem()     
                        {
                            Allowautoredirect = false,
                            URL = "http://a.hd.xiaomi.com/register/book/a/26",
                            Cookie = cookies,
                            ContentType = "application/x-www-form-urlencoded",
                       };
   resultLogin = helperLogin.GetHtml(itemLogin);//一直出错,页面访问都OK得,不知道什么原因。好像进入死循环一样,helperLogin.GetHtml 获取不到结果。

求大侠指点呀!!!!!!!!!!!!!!!!


补充内容 (2014-1-12 17:14):
string username=“18314045@qq.com",password="wgy201314";


1. 开通SVIP会员,免费下载本站所有源码,不限次数据,不限时间
2. 加官方QQ群,加官方微信群获取更多资源和帮助
3. 找站长苏飞做网站、商城、CRM、小程序、App、爬虫相关、项目外包等点这里
发表于 2014-1-13 08:14:11 | 显示全部楼层
你调试看看登录有没有成功
发表于 2014-1-13 10:19:18 | 显示全部楼层
经测试按楼主所说的方法登陆没有成功! 回报错误:签名值不合法
发表于 2014-1-13 10:24:23 | 显示全部楼层
无法浏览网页 发表于 2014-1-13 10:19
经测试按楼主所说的方法登陆没有成功! 回报错误:签名值不合法

那估计还是卡在了登录,还没有到这一步
 楼主| 发表于 2014-1-13 10:44:34 | 显示全部楼层
无法浏览网页 发表于 2014-1-13 10:19
经测试按楼主所说的方法登陆没有成功! 回报错误:签名值不合法

string username = "471555519@qq.com";// ldr.Cells[0].Value.ToString();
            string password ="wgy201314";//dr.Cells[2].Value.ToString();
           // string ls_yyurl=(string)parms[1];
            string Cookies = "";// (string)ldr.Cells[5].Value;
            HttpItem itemSign = new HttpItem()          //获取_sign
            {
                URL = "https://account.xiaomi.com/pass/serviceLogin",
            };
            HttpHelper httphelper = new HttpHelper();
            HttpResult httpresult = httphelper.GetHtml(itemSign);
            Cookies = httpresult.Cookie;
            HttpItem itemLogin = new HttpItem()         //登陆Post
            {
                URL = "https://account.xiaomi.com/pass/serviceLoginAuth2",
                Method = "POST",
                 Referer="https://account.xiaomi.com/pass/serviceLogin",
                ContentType = "application/x-www-form-urlencoded",
                Postdata = string.Format("passToken={0}&user={1}&pwd={2}&callback={3}&sid={4}&qs={5}&hidden={6}&_sign={7}", xmdata.PassToken, username, password, xmdata.CallBack, xmdata.SID, xmdata.QS, xmdata.HIDDEN, xmdata.SIGN)
            };
            HttpResult resultLogin = httphelper.GetHtml(itemLogin);//http://p.www.xiaomi.com/open/zt/version.html
            Cookies += ";" + resultLogin.Cookie;
            itemLogin = new HttpItem()
            {
                Allowautoredirect = false,
                URL = "https://account.xiaomi.com/pass/userInfo",
                Cookie = Cookies,
                ContentType = "application/x-www-form-urlencoded",
            };

            resultLogin = httphelper.GetHtml(itemLogin);//成功到个人账户页面
            Cookies += ";" + resultLogin.Cookie;
            itemLogin = new HttpItem()
            {
                Allowautoredirect = false,
                URL = "http://a.hd.xiaomi.com/register/book/a/26",
                Cookie = Cookies,
                ContentType = "application/x-www-form-urlencoded",
            };
            resultLogin = httphelper.GetHtml(itemLogin);//一直出错,捕捉不到数据 Allowautoredirect =true 好像进入重定向死循环,值得页面报403错误,,页面访问都OK得,不知道什么原因。好像进入死循环一样,helperLogin.GetHtml 获取不到结果。


 楼主| 发表于 2014-1-13 10:45:36 | 显示全部楼层
站长苏飞 发表于 2014-1-13 10:24
那估计还是卡在了登录,还没有到这一步

登陆成功的,代码贴后面:

string username = "471555519@qq.com";// ldr.Cells[0].Value.ToString();
            string password ="wgy201314";//dr.Cells[2].Value.ToString();
           // string ls_yyurl=(string)parms[1];
            string Cookies = "";// (string)ldr.Cells[5].Value;
            HttpItem itemSign = new HttpItem()          //获取_sign
            {
                URL = "https://account.xiaomi.com/pass/serviceLogin",
            };
            HttpHelper httphelper = new HttpHelper();
            HttpResult httpresult = httphelper.GetHtml(itemSign);
            Cookies = httpresult.Cookie;
            HttpItem itemLogin = new HttpItem()         //登陆Post
            {
                URL = "https://account.xiaomi.com/pass/serviceLoginAuth2",
                Method = "POST",
                 Referer="https://account.xiaomi.com/pass/serviceLogin",
                ContentType = "application/x-www-form-urlencoded",
                Postdata = string.Format("passToken={0}&user={1}&pwd={2}&callback={3}&sid={4}&qs={5}&hidden={6}&_sign={7}", xmdata.PassToken, username, password, xmdata.CallBack, xmdata.SID, xmdata.QS, xmdata.HIDDEN, xmdata.SIGN)
            };
            HttpResult resultLogin = httphelper.GetHtml(itemLogin);//http://p.www.xiaomi.com/open/zt/version.html
            Cookies += ";" + resultLogin.Cookie;
            itemLogin = new HttpItem()
            {
                Allowautoredirect = false,
                URL = "https://account.xiaomi.com/pass/userInfo",
                Cookie = Cookies,
                ContentType = "application/x-www-form-urlencoded",
            };

            resultLogin = httphelper.GetHtml(itemLogin);//成功到个人账户页面
            Cookies += ";" + resultLogin.Cookie;
            itemLogin = new HttpItem()
            {
                Allowautoredirect = false,
                URL = "http://a.hd.xiaomi.com/register/book/a/26",
                Cookie = Cookies,
                ContentType = "application/x-www-form-urlencoded",
            };
            resultLogin = httphelper.GetHtml(itemLogin);//一直出错,页面访问都OK得,不知道什么原因。好像进入死循环一样,helperLogin.GetHtml 获取不到结果。


发表于 2014-1-13 10:54:38 | 显示全部楼层
Allowautoredirect = false,是不会执行重向的。
 楼主| 发表于 2014-1-13 10:57:05 | 显示全部楼层
对呀,我如果改成true 的话就会报错了,403,好像死循环了
 楼主| 发表于 2014-1-13 10:57:42 | 显示全部楼层
/////我调整了下,拷贝代码可以直接执行-------------  
string username = "471555519@qq.com";// ldr.Cells[0].Value.ToString();
            string password ="wgy201314";//dr.Cells[2].Value.ToString();
           // string ls_yyurl=(string)parms[1];
            string Cookies = "";// (string)ldr.Cells[5].Value;
            HttpItem itemSign = new HttpItem()          //获取_sign
            {
                URL = "https://account.xiaomi.com/pass/serviceLogin",
            };
            HttpHelper httphelper = new HttpHelper();
            HttpResult httpresult = httphelper.GetHtml(itemSign);
            Cookies = httpresult.Cookie;
               string CallBack = System.Uri.EscapeDataString(Regex.Match(httpresult.Html, "(?<=callback = encodeURIComponent\\(\").*\"").Value.ToString().Replace("\"", ""));
               string SID = System.Uri.EscapeDataString(Regex.Match(httpresult.Html, "(?<=sid = encodeURIComponent\\(\").*\"").Value.ToString().Replace("\"", ""));
               string QS = System.Uri.EscapeDataString(Regex.Match(httpresult.Html, "(?<=qs = encodeURIComponent\\(\").*\"").Value.ToString().Replace("\"", ""));
               string SIGN = System.Uri.EscapeDataString(Regex.Match(httpresult.Html, "(?<=sign = encodeURIComponent\\(\").*\"").Value.ToString().Replace("\"", ""));
               string HIDDEN = System.Uri.EscapeDataString(Regex.Match(httpresult.Html, "(?<=hidden = encodeURIComponent\\(\").*\"").Value.ToString().Replace("\"", ""));
               string FrameSrc = System.Uri.EscapeDataString(Regex.Match(httpresult.Html, "(?<=var iframeSrc = \").*\"").Value.ToString().Replace("\"", ""));
            HttpItem itemLogin = new HttpItem()         //登陆Post
            {
                URL = "https://account.xiaomi.com/pass/serviceLoginAuth2",
                Method = "POST",
                 Referer="https://account.xiaomi.com/pass/serviceLogin",
                ContentType = "application/x-www-form-urlencoded",
                Postdata = string.Format("passToken={0}&user={1}&pwd={2}&callback={3}&sid={4}&qs={5}&hidden={6}&_sign={7}", "", username, password, CallBack, SID, QS, HIDDEN, SIGN)
            };
            HttpResult resultLogin = httphelper.GetHtml(itemLogin);//http://p.www.xiaomi.com/open/zt/version.html
            Cookies += ";" + resultLogin.Cookie;
            itemLogin = new HttpItem()
            {
                Allowautoredirect = false,
                URL = "https://account.xiaomi.com/pass/userInfo",
                Cookie = Cookies,
                ContentType = "application/x-www-form-urlencoded",
            };

            resultLogin = httphelper.GetHtml(itemLogin);//成功到个人账户页面
            Cookies += ";" + resultLogin.Cookie;
            itemLogin = new HttpItem()
            {
                Allowautoredirect = false,
                URL = "http://a.hd.xiaomi.com/register/book/a/26",
                Cookie = Cookies,
                ContentType = "application/x-www-form-urlencoded",
            };
            resultLogin = httphelper.GetHtml(itemLogin);//一直出错,页面访问都OK得,不知道什么原因。好像进入死循环一样,helperLogin.GetHtml 获取不到结果。
         
发表于 2014-1-13 11:05:17 | 显示全部楼层
不要使用字符串Cookie试下,这应该还是验证问题,就是Cookie不正确。或者是参数有问题。
正常访问页面 ContentType = "application/x-www-form-urlencoded",怎么能这样设置呢?
您需要登录后才可以回帖 登录 | 马上注册

本版积分规则

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

GMT+8, 2024-5-6 05:55

© 2014-2021

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