|
求住我用了你的HttpHelper类登录微淘,可以说正常情况下是没有问题的。如果在多次输入密码错误或者多次登录出现了验证码,我也是获取到验证码了,然后拼接起来提交怎么都不行,求指教,代码如下:
- <p> HttpItem item = new HttpItem();
- string cookie = "";
- </p><p> string name="XXX"
-
- item.URL = string.Format(
-
- "<a >https://login.taobao.com/member/request_nick_check.do?_ksTS=1377391470565_83&_input_charset=utf-8&username={0</a>}",
-
- HttpUtility.UrlEncode(userName));
-
- item.Method = "get";
-
- item.Accept = "Accept application/json, text/javascript, */*; q=0.01";
- HttpResult result = m_Http.GetHtml(item);
- string html = result.Html;
- cookie = result.Cookie;</p><p>
- <font color="red">//第一步判断是否要输入验证码:</font>
-
- Match needcode = Regex.Match(html, "(?<="needcode":)\\w+");</p><p> if (needcode.Value == "false")
- {
- <font color="red"> //模拟登录完全没有问题</font>
- }</p><p>else
- //有验证码</p><p> {</p><p> //首先得到验证码
- 把它保存到一个目录Codeimg
- Match sessionid = Regex.Match(cookie, "(?<=cookie2=)\\w+");
- item.URL =string.Format( "<a >https://regcheckcode.taobao.com/auction/checkcode?sessionID={0}&rad=0.3025266655735114&_r_=1377393595015</a>", sessionid);
- item.Method = "get";
- item.ResultType = ResultType.Byte;
- item.Accept = "image/png, image/svg+xml, image/*;q=0.8, */*;q=0.5";
-
- result = m_Http.GetHtml(item);
- html = result.Html;
-
- String path =
- HttpContext.Current.Request.MapPath("/Codeimg");
-
- FileUtil.CreateFolder(path);
-
- path = path + "<a href="file://taobao-code.jpg/">\\taobao-code.jpg</a>";
-
- FileUtil.writeBytes(path, result.ResultByte);</p>
- //开始模拟登录
- item.URL = "<a >https://login.taobao.com/member/login.jhtml</a>";
- //URL 必需项
- item.Method = "post"; //URL 可选项 默认为Get
- //下面使用POST方式提交用户名和密码,为什么用POST?因为HttpWatch上面有
- item.Postdata =
- string.Format("ua=<font color="#ff0000">数据见帖子下面</font>","用户名","密码","这里填写生成的验证码");<font color="red"> //Post数据
- 这个是我安装你的方法抓取</font>
-
- item.ContentType = "application/x-www-form-urlencoded;
- charset=UTF-8";//返回类型 可选项有默认值
- item.Allowautoredirect = true;//是否根据301跳转 可选项
- HttpResult result1 =m_Http.GetHtml(item);
- string html1 = result1.Html;
- string cookie1 = result1.Cookie;
- Match m1 = Regex.Match(html1, "(?<=,"message":").*?(?=",)");
- <p> <font color="red"> //在这个token
- 取不到,html直接跑首页去了。如果Post用你之前写阿里妈妈里面的那个,直接报验证码输入失败,我确认了弹出框输入验证码正确了的,怎么也不行,弄的快要疯了,求指点</font>
- </p><p> }</p>
复制代码 |
|