京东价格监控软件开发技术探讨三:使用C#模拟京东登录

使用C#模拟京东登录

京东模拟登录步骤
第一步:获取登录页面基础值
第二步:判断是否需要验证码
第三步:拼装提交信息
第四步:提交数据到指定服务
第五步:获取返回信息

先上一段登录代码:

                HttpItem item = new HttpItem();
                HttpHelper helper = new HttpHelper();
                HttpResult result = new HttpResult();
                item.URL = string.Format("https://passport.jd.com/uc/loginService?uuid={0}&&r={1}&version=2015", _jdLoginer.uuid, _jdLoginer.r);
                item.Method = "post";
                item.Allowautoredirect = true;
                item.ContentType = "application/x-www-form-urlencoded; charset=UTF-8";
                item.Postdata = string.Format("uuid={0}&machineNet=&machineCpu=&machineDisk=&eid={1}&fp={2}&{3}={4}"
                    + "&loginname={5}&nloginpwd={6}&loginpwd={6}&chkRememberMe=on&authcode=",
                    _jdLoginer.uuid, _jdLoginer.eid, _jdLoginer.fp, _jdLoginer.tname, _jdLoginer.tvalue, _jdLoginer.loginname,_jdLoginer.loginpwd);
                item.Header.Add("x-requested-with", "XMLHttpRequest");
                item.Header.Add("Accept-Encoding", "gzip, deflate");
                item.Accept = "*/*";
                item.Encoding = Encoding.UTF8;
                item.Cookie = cookies;
                result = helper.GetHtml(item);

                if (!result.Html.Contains("success"))
                {
                    if (result.Html.ToLower().Contains("pwd"))
                    {
                        MessageBox.Show("密码验证不通过!", "系统提示");
                        return;
                    }
                    else if (result.Html.ToLower().Contains("emptyauthcode"))
                    {
                        MessageBox.Show("请输入登录验证码!", "系统提示");
                        return;
                    }
                    else
                    {
                        MessageBox.Show("登陆失败!" + result.Html, "系统提示");
                    }
                }
                else
                {
                    MessageBox.Show("登录京东商城成功!", "系统提示");
                }

京东登录模型

    public class JDLogin
    {
        /// <summary>
        /// 当前帐号临时编号
        /// </summary>
        public string uuid { get;set;}
        public string machineNet { get; set; }
        public string machineCpu { get; set; }
        public string machineDisk { get; set; }
        /// <summary>
        /// 随机数
        /// </summary>
        public string r { get; set; }
        /// <summary>
        /// 
        /// </summary>
        public string eid { get; set; }
        /// <summary>
        /// sessionId
        /// </summary>
        public string fp { get; set; }
        /// <summary>
        /// key键
        /// </summary>
        public string tname { get; set; }
        /// <summary>
        /// key值
        /// </summary>
        public string tvalue { get; set; }
        /// <summary>
        /// 登录名
        /// </summary>
        public string loginname { get; set; }
        /// <summary>
        /// 登录密码
        /// </summary>
        public string nloginpwd { get; set; }
        /// <summary>
        /// 登录密码
        /// </summary>
        public string loginpwd { get; set; }
        /// <summary>
        /// 记住账号信息
        /// </summary>
        public string chkRememberMe { get; set; }
        /// <summary>
        /// 验证码
        /// </summary>
        public string authcode { get; set; }
    }

杀京东 做最走心的京东价格监控软件 免费开源的价格监控软件 欢迎加入QQ群415014949一起讨论


  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
# JD_AutoBuy ## 京东抢购 Python爬虫,自动登录京东网站,查询商品库存,价格,显示购物车详情等。 可以指定抢购商品,自动购买下单,然后手动去京东付款就行。 ## chang log + 2017-03-30 实现二维码扫码登陆 ## 运行环境 Python 2.7 ## 第方库 - [Requests][1]: 简单好用,功能强大的Http请求库 - [beautifulsoup4][2]: HTML文档格式化及便签选择器 ## 环境配置 ``` Python pip install requests pip install beautifulsoup4 ``` ## 使用帮助 ``` cmd > python scraper-jd.py -h usage: scraper-jd.py [-h] [-u USERNAME] [-p PASSWORD] [-g GOOD] [-c COUNT] [-w WAIT] [-f] [-s] Simulate to login Jing Dong, and buy sepecified good optional arguments: -h, --help show this help message and exit -u USERNAME, --username USERNAME Jing Dong login user name -p PASSWORD, --password PASSWORD Jing Dong login user password -g GOOD, --good GOOD Jing Dong good ID -c COUNT, --count COUNT The count to buy -w WAIT, --wait WAIT Flush time interval, unit MS -f, --flush Continue flash if good out of stock -s, --submit Submit the order to Jing Dong ``` ## 实例输出 ``` cmd +++++++++++++++++++++++++++++++++++++++++++++++++++++++ Thu Mar 30 17:10:01 2017 > 请打开京东手机客户端,准备扫码登陆: 201 : 二维码未扫描 ,请扫描二维码 201 : 二维码未扫描 ,请扫描二维码 201 : 二维码未扫描 ,请扫描二维码 201 : 二维码未扫描 ,请扫描二维码 202 : 请手机客户端确认登录 200 : BADACIFYhf6fakfHvjiYTlwGzSp4EjFATN3Xw1ePR1hITtw0 登陆成功 +++++++++++++++++++++++++++++++++++++++++++++++++++++++ Thu Mar 30 17:10:28 2017 > 商品详情 编号:3133857 库存:现货 价格:6399.00 名称:Apple iPhone 7 Plus (A1661) 128G 黑色 移动联通电信4G手机 链接:http://cart.jd.com/gate.action?pid=3133857&pcount=1&ptype=1 商品已成功加入购物车! 购买数量:3133857 > 1 +++++++++++++++++++++++++++++++++++++++++++++++++++++++ Thu Mar 30 17:10:30 2017 > 购物车明细 购买 数量 价格 总价 商品 Y 1 6399.00 6399.00 Apple iPhone 7 Plus (A1661) 128G 黑色 移动联通电信4G手机 总数: 1 总额: 6399.00 +++++++++++++++++++++++++++++++++++++++++++++++++++++++ Thu Mar 30 17:10:30 2017 > 订单详情 +++++++++++++++++++++++++++++++++++++++++++++++++++++++ ... ``` ## 注 代码仅供学习之用,京东网页不断变化,代

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值