苏飞论坛

 找回密码
 马上注册

QQ登录

只需一步,快速开始

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

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

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

查看: 13325|回复: 5

[其他] 求住HttpHelper类登录微淘有验证码模拟登录不了

[复制链接]
发表于 2013-8-25 22:41:15 | 显示全部楼层 |阅读模式
求住我用了你的HttpHelper类登录微淘,可以说正常情况下是没有问题的。如果在多次输入密码错误或者多次登录出现了验证码,我也是获取到验证码了,然后拼接起来提交怎么都不行,求指教,代码如下:

  1. <p>   HttpItem item = new HttpItem();
  2.                  string cookie = "";
  3. </p><p> string name="XXX"
  4.                
  5. item.URL =  string.Format(
  6.                         
  7. "<a >https://login.taobao.com/member/request_nick_check.do?_ksTS=1377391470565_83&_input_charset=utf-8&username={0</a>}",
  8.                         
  9. HttpUtility.UrlEncode(userName));
  10.                
  11. item.Method = "get";
  12.                
  13. item.Accept = "Accept application/json, text/javascript, */*; q=0.01";
  14. HttpResult result = m_Http.GetHtml(item);
  15.      string html   = result.Html;
  16.    cookie = result.Cookie;</p><p>      
  17. <font color="red">//第一步判断是否要输入验证码:</font>
  18.                  
  19. Match needcode = Regex.Match(html, "(?<="needcode":)\\w+");</p><p>    if (needcode.Value == "false")
  20.    {        
  21. <font color="red">     //模拟登录完全没有问题</font>     
  22. }</p><p>else
  23. //有验证码</p><p>  {</p><p> //首先得到验证码
  24. 把它保存到一个目录Codeimg
  25. Match sessionid = Regex.Match(cookie, "(?<=cookie2=)\\w+");                  
  26. item.URL =string.Format( "<a >https://regcheckcode.taobao.com/auction/checkcode?sessionID={0}&rad=0.3025266655735114&_r_=1377393595015</a>", sessionid);        
  27. item.Method = "get";         
  28. item.ResultType = ResultType.Byte;                    
  29. item.Accept = "image/png, image/svg+xml, image/*;q=0.8, */*;q=0.5";
  30.                   
  31. result = m_Http.GetHtml(item);                    
  32. html = result.Html;
  33.                     
  34. String path =
  35. HttpContext.Current.Request.MapPath("/Codeimg");
  36.                     
  37. FileUtil.CreateFolder(path);
  38.                     
  39. path = path + "<a href="file://taobao-code.jpg/">\\taobao-code.jpg</a>";
  40.                     
  41. FileUtil.writeBytes(path, result.ResultByte);</p>               
  42. //开始模拟登录            
  43. item.URL = "<a >https://login.taobao.com/member/login.jhtml</a>";
  44. //URL     必需项                 
  45. item.Method = "post"; //URL     可选项 默认为Get                  
  46. //下面使用POST方式提交用户名和密码,为什么用POST?因为HttpWatch上面有               
  47. item.Postdata =
  48. string.Format("ua=<font color="#ff0000">数据见帖子下面</font>","用户名","密码","这里填写生成的验证码");<font color="red"> //Post数据   
  49. 这个是我安装你的方法抓取</font>
  50.                     
  51. item.ContentType = "application/x-www-form-urlencoded;

  52. charset=UTF-8";//返回类型    可选项有默认值               
  53. item.Allowautoredirect = true;//是否根据301跳转     可选项                       
  54. HttpResult result1 =m_Http.GetHtml(item);
  55.   string html1 = result1.Html;                 
  56. string cookie1 = result1.Cookie;               
  57. Match m1 = Regex.Match(html1, "(?<=,"message":").*?(?=",)");
  58. <p>                   <font color="red"> //在这个token
  59. 取不到,html直接跑首页去了。如果Post用你之前写阿里妈妈里面的那个,直接报验证码输入失败,我确认了弹出框输入验证码正确了的,怎么也不行,弄的快要疯了,求指点</font>
  60. </p><p>          }</p>
复制代码


1. 开通SVIP会员,免费下载本站所有源码,不限次数据,不限时间
2. 加官方QQ群,加官方微信群获取更多资源和帮助
3. 找站长苏飞做网站、商城、CRM、小程序、App、爬虫相关、项目外包等点这里
 楼主| 发表于 2013-8-25 22:41:43 | 显示全部楼层
//提交的数据
item.Postdata =
string.Format("ua=198u5ObXObBitH2MRZepLykPFTchByE%2FLSTSZM%3D%7CuKBnf0c%2FRw83TzcvN08XH8U%3D%7CuZFW7MtSC4eLQLuXzODHACeviE9oEoli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6dgt9%2FnIPef1xDHr%2Fcw54%2FnIPd%2FB8AXb%2Fct&TPL_username={0}&TPL_password={1}&TPL_checkcode={2}&need_check_code=true&loginsite=0&newlogin=0&TPL_redirect_url=http%3A%2F%2Fi.taobao.com%2Fmy_taobao.htm%3Fnekot%3DZHVsZWkxOTkwMDgxNQ%253D%253D1377437697827&from=tb&fc=default&style=default&css_style=&tid=XOR_1_000000000000000000000000000000_625A4756410E7578087C0071&support=000001&CtrlVersion=1%2C0%2C0%2C7&loginType=3&minititle=&minipara=&umto=NaN&pstrong=1&llnick=&sign=&need_sign=&isIgnore=&full_redirect=&popid=&callback=&guf=&not_duplite_str=&need_user_id=&poy=&gvfdcname=10&gvfdcre=687474703A2F2F6C6F67696E2E74616F62616F2E636F6D2F6D656D6265722F6C6F676F75742E6A68746D6C3F73706D3D61317A30322E312E302E302E30626B52476F26663D746F70266F75743D7472756526726564697265637455524C3D68747470253341253246253246692E74616F62616F2E636F6D2532466D795F74616F62616F2E68746D2533466E656B6F742533445A4856735A576B784F546B774D4467784E512532353344253235334431333737343337363937383237&from_encoding=&sub=&oslanguage=&sr=1366*768&osVer=windows%7C6.2&naviVer=ie%7C8","用户名","密码","这里填写生成的验证码"); //Post数据
发表于 2013-8-26 08:16:31 | 显示全部楼层
如果有验证码,获取验证码时要带着第一次访问登录页面时的Cookie,这样才能保证是同一个会话,你输入的验证码才能有效,如果不带就相当于你在A电脑看到的验证码,在B电脑上进行登录输入,这肯定是是不行的。
 楼主| 发表于 2013-8-26 12:18:31 | 显示全部楼层
站长苏飞 发表于 2013-8-26 08:16
如果有验证码,获取验证码时要带着第一次访问登录页面时的Cookie,这样才能保证是同一个会话,你输入的验证 ...

第一次访问登录页面时的Cookie应该是获取的,那我后面验证码快应该怎么复制给另外的一个会话呢,也就是cookie 赋值问题?
发表于 2013-8-26 12:30:29 | 显示全部楼层
多看下抓包,看是什么时候判断账号是否需要验证码,比如百度 是填完账号光标离开账号编辑框的时候会GET一个网址获得验证码数据(数据必须有账号,比如百度是需要账号还有一个cookie和时间戳),这样才是你账号的验证码地址字符串(一般验证码还需要拼接成链接),而在post的时候还需要告诉你的验证码地址  下边是百度GET验证码获取地址 供参考



https://passport.baidu.com/v2/ap ... dex=0&username=用户名&isphone=false&time=时间戳

发表于 2013-8-26 12:52:04 | 显示全部楼层
item.Cookie给这个赋值就行了,把result.Cookie里面的Cookie赋值给前面的Item里的Cookie,这是HttpHelper使用的基础,你看教程里面都有写到。
如果不太熟悉就看看教程里面的Cookie二次使用是怎么操作的
http://www.sufeinet.com/thread-3-1-1.html
您需要登录后才可以回帖 登录 | 马上注册

本版积分规则

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

GMT+8, 2024-12-27 21:25

© 2014-2021

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