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

苏飞论坛

 找回密码
 马上注册

QQ登录

只需一步,快速开始

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

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

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

查看: 9472|回复: 5

HttpHelper模拟登录,登进去就行。获取登录后Cookie!

[复制链接]
发表于 2014-3-31 11:26:05 | 显示全部楼层 |阅读模式
提需求
联系方式: 383957779
金额: 20 元
本帖最后由 daekow 于 2014-3-31 11:58 编辑

http://wk.j-pay.cn/V3/user/Login
帐号:13367498297
密码:jkicomka
HttpHelper模拟登录,登进去就行。获取登录后Cookie!

附代码:
AutoMoney.rar (663.58 KB, 下载次数: 313)


1. 开通SVIP会员,免费下载本站所有源码,不限次数据,不限时间
2. 加官方QQ群,加官方微信群获取更多资源和帮助
3. 找站长苏飞做网站、商城、CRM、小程序、App、爬虫相关、项目外包等点这里
发表于 2014-3-31 12:10:54 | 显示全部楼层
[C#] 纯文本查看 复制代码
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Drawing;
using System.IO;
using DotNet4.Utilities;
using System.Runtime.InteropServices;
using System.Net;
using System.Security;
using System.Security.Permissions;
using System.ComponentModel;
namespace AutoMoney
{
    public class JPay
    {
        HttpHelper http = new HttpHelper();

        public CookieCollection Cookie;

        public bool Login(string name, string pwd)
        {
            #region 打开登录页面
            HttpItem item = new HttpItem();
            item.URL = "http://weike.j-pay.cn/v3/user/login";
            item.ResultCookieType = ResultCookieType.CookieCollection;
            HttpResult result = http.GetHtml(item);
            #endregion

            #region 截取需要的参数
            string html = result.Html;
            int start = html.IndexOf("value=", html.IndexOf("看不清")) + 7;
            int len = html.IndexOf("\" />", start) - start;
            string _tokenName_ = html.Substring(start, len);
            start = html.IndexOf("CaptchaDeText");
            len = html.IndexOf("\"", start) - start;
            string captchaDeText = html.Substring(start, len);
            start = html.IndexOf("value=", html.IndexOf("__Request")) + 7;
            len = html.IndexOf("\" />", start) - start;
            string __RequestVerificationToken = html.Substring(start, len);
            #endregion

            #region 获取验证码
            item = new HttpItem();
            item.URL = "http://weike.j-pay.cn/DefaultCaptcha/Generate?t=" + _tokenName_;
            item.ResultType = ResultType.Byte;
            item.CookieCollection=result.CookieCollection;
            item.ResultCookieType = ResultCookieType.CookieCollection;
            item.Accept = "image/png, image/svg+xml, image/*;q=0.8, */*;q=0.5";
            item.Referer = "http://weike.j-pay.cn/v3/user/login";
            result = http.GetHtml(item);
            #endregion

            #region 验证码破解
            IntPtr re = Dc.RecByte_A(result.ResultByte, result.ResultByte.Length, G.USER_ID, G.USER_PWD, "5134");
            string returnMess = Marshal.PtrToStringAnsi(re);
            string code = "";
            if (returnMess.IndexOf("|") > -1)
            {
                code = returnMess.Split('|')[0];
                if (code.Length != 5)
                {
                    Dc.ReportError_A(G.USER_ID, returnMess.Split('|')[2]);
                    return false;
                }
            }
            else
            {
                return false;
            }
            #endregion

            #region 提交登录请求
            item = new HttpItem();
            item.Encoding = Encoding.UTF8;
            item.URL = "http://weike.j-pay.cn/V3/user/Login";
            item.Method = "post";
            item.CookieCollection = result.CookieCollection;
            item.ResultCookieType = ResultCookieType.CookieCollection;
            item.Postdata = string.Format("CaptchaFormElementId=form0&ResetFormElementId=form0&SuccessSummaryContainerElementId=operator-LoginModel-success-div&ValidationSummaryContainerElementId=operator-LoginModel-validation-div&X-Requested-With=XMLHttpRequest&UserName={0}&Password={1}&CaptchaInputText={2}&_tokenName_={3}&{3}={4}&__RequestVerificationToken={5}", name, pwd, code, captchaDeText, _tokenName_, __RequestVerificationToken);
            item.ResultType = ResultType.String;
            item.Accept = "*/*";
            item.ContentType = "application/x-www-form-urlencoded; charset=UTF-8";
            item.Host = "weike.j-pay.cn";
            item.Referer = "http://weike.j-pay.cn/v3/user/login";
            
            result = http.GetHtml(item);
            #endregion

            html = result.Html;

            Cookie = result.CookieCollection;
            return false;
        }
    }
}
 楼主| 发表于 2014-3-31 12:40:55 | 显示全部楼层
站长苏飞 发表于 2014-3-31 12:10
[mw_shl_code=csharp,true]using System;
using System.Collections.Generic;
using System.Linq;

远程服务器返回错误: (500) 内部服务器错误。
 楼主| 发表于 2014-3-31 13:31:38 | 显示全部楼层
daekow 发表于 2014-3-31 12:40
远程服务器返回错误: (500) 内部服务器错误。

<script type="text/javascript">
    var html = "<ul><li>登录成功,2秒钟后页面自行跳转</li></ul>";
    $("#operator-LoginModel-success-div").html(html).fadeIn(500).delay(5000).fadeOut(500);
   


        $(document).ready(function(){
window.location.href="/v3/home/index";        });
</script>


现在可以登录了,有跳转怎么弄。CookieCollection是空的
发表于 2014-3-31 13:35:40 | 显示全部楼层
daekow 发表于 2014-3-31 12:40
远程服务器返回错误: (500) 内部服务器错误。

登录后未发现有Cookie返回。
发表于 2014-3-31 13:47:19 | 显示全部楼层
使用字符串的Cookie,跳转不用管,不要跳转,直接用这个Cookie应该就是登录成功了,
您需要登录后才可以回帖 登录 | 马上注册

本版积分规则

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

GMT+8, 2024-5-12 10:44

© 2014-2021

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