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

苏飞论坛

 找回密码
 马上注册

QQ登录

只需一步,快速开始

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

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

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

楼主: zbsgift

[求助] 关于京东post数据格式问题

[复制链接]
 楼主| 发表于 2014-2-16 13:12:20 | 显示全部楼层
然后看到了,服务器返回的信息,然后蛋疼了。。。
明明我想注册的用户id没被注册过,结果服务器返回的结果是【({"info":"该用户名已被使用,请使用其它用户名注册"})】


1. 开通SVIP会员,免费下载本站所有源码,不限次数据,不限时间
2. 加官方QQ群,加官方微信群获取更多资源和帮助
3. 找站长苏飞做网站、商城、CRM、小程序、App、爬虫相关、项目外包等点这里
 楼主| 发表于 2014-2-16 13:18:39 | 显示全部楼层
我觉得可能是验证码的问题,因为我随便乱输入一个验证码,也是这结果。
验证码的话,我是这样去取的。
先到注册登录页面,然后把验证码的url得到,在请求得到。【https://authcode.jd.com/verify/i ... p;yys=1392527751983
由于最后有个时间的随机数,我在想是不是我虽然用这个url去请求了,但其实和注册登录页面显示的图片是不一样的?
 楼主| 发表于 2014-2-16 14:33:01 | 显示全部楼层
[C#] 纯文本查看 复制代码
namespace creatJDID
{
    public partial class Form1 : Form
    {
        HttpItem itemReg = null;
        HttpHelper http = null;
        private string uuid = "";
        private string name = "";
        private string value = "";

        public Form1()
        {
            InitializeComponent();
            http = new HttpHelper();
            itemReg = new HttpItem();
        }

        private void button1_Click(object sender, EventArgs e)
        {
            HttpItem item = new HttpItem()
            {

                URL = "https://reg.jd.com/reg/person?ReturnUrl=http%3A//www.jd.com/",//URL     必需项

                Encoding = null,//编码格式(utf-8,gb2312,gbk)     可选项 默认类会自动识别

                Method = "GET",//URL     可选项 默认为Get

                IsToLower = false,//得到的HTML代码是否转成小写     可选项默认转小写

                Cookie = "",//字符串Cookie     可选项

                UserAgent = "Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/32.0.1700.107 ",//用户的浏览器类型,版本,操作系统     可选项有默认值

                Accept = "text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,*/*;q=0.8",//    可选项有默认值

                ContentType = "text/html;charset=GBK",//返回类型    可选项有默认值

                Referer = "http://www.jd.com/",//来源URL     可选

                Allowautoredirect = true,//是否根据301跳转     可选项

                Postdata = "",//Post数据     可选项GET时不需要写

                PostDataType = PostDataType.String,//默认为传入String类型,也可以设置PostDataType.Byte传入Byte类型数据

                ResultType = ResultType.String,//返回数据类型,是Byte还是String

                CookieCollection = new System.Net.CookieCollection(),//可以直接传一个Cookie集合进来

                ResultCookieType = ResultCookieType.CookieCollection

            };
            
            HttpResult result = http.GetHtml(item);
            itemReg.Cookie = result.Cookie;
            itemReg.CookieCollection = result.CookieCollection;

            if (!checkName("Blue200-gift14", result))
            {
                MessageBox.Show("此用户已注册!");
                return;
            }

            string pattern1 = "<input type=\"hidden\" name=\"uuid\" id=\"uuid\" value=\"(\\S+?)\"/>";
            string pattern2 = "<input type=\"hidden\" name=\"(\\S+?)\" value=\"(\\S+?)\"/>";
            Match match1 = Regex.Match(result.Html, pattern1, RegexOptions.IgnoreCase);
            Match match2 = Regex.Match(result.Html, pattern2, RegexOptions.IgnoreCase);
            uuid = match1.Groups[1].Value;
            name = match2.Groups[1].Value;
            value = match2.Groups[1].Value;
            string findisvalue = result.Html.Substring(result.Html.IndexOf("srcid=reg&is=") + 17, 32);
            string time = GetTimeLikeJS().ToString();
            string imageUrl = "https://authcode.jd.com/verify/image?a=0&acid=" + uuid + "&";
            imageUrl = imageUrl + "uid=" + uuid + "&";
            imageUrl = imageUrl + "srcid=" + "reg" + "&";
            imageUrl = imageUrl + "is=" + findisvalue + "&";
            imageUrl = imageUrl + "yys=" + time;

            HttpItem item2 = new HttpItem()
            {

                URL = imageUrl,//URL     必需项

                Encoding = null,//编码格式(utf-8,gb2312,gbk)     可选项 默认类会自动识别

                Method = "GET",//URL     可选项 默认为Get

                IsToLower = false,//得到的HTML代码是否转成小写     可选项默认转小写

                Cookie = result.Cookie,//字符串Cookie     可选项

                UserAgent = "Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/32.0.1700.107 ",//用户的浏览器类型,版本,操作系统     可选项有默认值

                Accept = "image/webp,*/*;q=0.8",//    可选项有默认值

                ContentType = "image/jpeg",//返回类型    可选项有默认值

                Referer = "https://reg.jd.com/reg/person?ReturnUrl=http%3A//www.jd.com/",//来源URL     可选

                Allowautoredirect = true,//是否根据301跳转     可选项

                Postdata = "",//Post数据     可选项GET时不需要写

                PostDataType = PostDataType.String,//默认为传入String类型,也可以设置PostDataType.Byte传入Byte类型数据

                ResultType = ResultType.Byte,//返回数据类型,是Byte还是String

                CookieCollection = result.CookieCollection,//可以直接传一个Cookie集合进来

                ResultCookieType = ResultCookieType.CookieCollection

            };

            HttpResult result2 = http.GetHtml(item2);
            pictureBox1.Image = byteArrayToImage(result2.ResultByte);
        }


        private long GetTimeLikeJS()
        {

            long lLeft = 621355968000000000;

            DateTime dt = DateTime.Now;

            long Sticks = (dt.Ticks - lLeft) / 10000;

            return Sticks;

        }

        private Image byteArrayToImage(byte[] Bytes)
        {
            using (MemoryStream ms = new MemoryStream(Bytes))
            {
                Image outputImg = Image.FromStream(ms);
                return outputImg;
            }
        }

        private void button2_Click(object sender, EventArgs e)
        {
            string userName = "Blue200-gift14";
            string pwd = "anny1034";
            string authcode = this.textBox1.Text;
            string postdata = "regType=person&";
            postdata += "uuid=" + uuid + "&";
            postdata += "regName=" + userName + "&";
            postdata += "schoolid=" + "&";
            postdata += "pwd=" + pwd + "&";
            postdata += "pwdRepeat=" + pwd + "&";
            postdata += "authcode=" + authcode + "&";
            postdata += "mobileCode="  + "&";
            postdata += name +"=" + value;
            Random rdm = new Random();
            string randomDouble = rdm.NextDouble().ToString();
            itemReg.Host = "reg.jd.com";
            //itemReg.URL = "https://reg.jd.com/reg/regService?r=0.5679832081886162&ReturnUrl=http%3A//www.jd.com/";
            itemReg.URL = "https://reg.jd.com/reg/regService?r="+randomDouble+"&ReturnUrl=http%3A//www.jd.com/";
            itemReg.Accept = "*/*";
            itemReg.Referer = "https://reg.jd.com/reg/person?ReturnUrl=http%3A//www.jd.com/";
            //itemReg.ContentType = "application/x-www-form-urlencoded; charset=utf-8";
            itemReg.Method = "POST";
            itemReg.PostDataType = PostDataType.String;
            itemReg.Postdata = postdata;
            itemReg.UserAgent = "Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/32.0.1700.107 Safari/537.36";
            itemReg.ResultType = ResultType.String;
            itemReg.Allowautoredirect = true;

            HttpResult result3 = http.GetHtml(itemReg,"1");

            string flg = result3.Html.Substring(result3.Html.IndexOf("success")+9,4);
        }

        private bool checkName(string name, HttpResult result)
        {
            HttpItem item = new HttpItem()
            {

                URL = "https://reg.jd.com/validate/isPinEngaged?pin=" + name + "&r=0.5163940236997528",//URL     必需项

                Encoding = null,//编码格式(utf-8,gb2312,gbk)     可选项 默认类会自动识别

                Method = "GET",//URL     可选项 默认为Get

                IsToLower = false,//得到的HTML代码是否转成小写     可选项默认转小写

                Cookie = result.Cookie,//字符串Cookie     可选项

                UserAgent = "Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/32.0.1700.107 ",//用户的浏览器类型,版本,操作系统     可选项有默认值

                Accept = "application/json, text/javascript, */*",//    可选项有默认值

                ContentType = "image/jpeg",//返回类型    可选项有默认值

                Referer = "https://reg.jd.com/reg/person?ReturnUrl=http%3A//www.jd.com/",//来源URL     可选

                Host = "reg.jd.com",

                Allowautoredirect = true,//是否根据301跳转     可选项

                Postdata = "",//Post数据     可选项GET时不需要写

                PostDataType = PostDataType.String,//默认为传入String类型,也可以设置PostDataType.Byte传入Byte类型数据

                ResultType = ResultType.Byte,//返回数据类型,是Byte还是String

                CookieCollection = result.CookieCollection,//可以直接传一个Cookie集合进来

                ResultCookieType = ResultCookieType.CookieCollection

            };

            HttpResult result2 = http.GetHtml(item);

            if (result2.Html.Contains("success"))
            {
                return true;

            }
            else 
            {
                return false;
            }
        }
    }
}

 楼主| 发表于 2014-2-16 14:36:46 | 显示全部楼层
button1 是先到注册页面,获取必要值和验证码url,然后显示到控件上
button2 是post提交注册,但结果一直提示【({"info":"该用户名已被使用,请使用其它用户名注册"})】
http.GetHtml(itemReg,"1");这个是重写了个方法,只是编码格式问题。

飞哥,麻烦帮我看看到底是不是验证码这一块出了问题啊
 楼主| 发表于 2014-2-16 15:27:18 | 显示全部楼层
是不是因为我获取页面 和获取验证码不是同步的,所以才导致这个问题啊,是的话 应该怎样才能同步获取呢
给个思路啊
发表于 2014-2-16 17:00:39 | 显示全部楼层
Encoding = null,//编码格式(utf-8,gb2312,gbk)     可选项 默认类会自动识别
这不是可以设置吗?你自己就可以设置啊,
 楼主| 发表于 2014-2-16 17:56:05 | 显示全部楼层
站长苏飞 发表于 2014-2-16 17:00
Encoding = null,//编码格式(utf-8,gb2312,gbk)     可选项 默认类会自动识别
这不是可以设置吗?你自己 ...

这个问题解决了。。。现在是验证码的问题。
第一次请求注册页面,里面没验证码,然后请求验证码链接,得到图片,然后在输入图片内容,再post过去的时候,提示出错。
网上说请求得到验证码的时候,要把cooike记下来,然后post的时候一起提交过去。但问题是
验证码获取链接 返回过来的内容里 没cooike啊
发表于 2014-2-16 18:58:27 | 显示全部楼层
那就使用登录页面的cookie获取验证码,然后登录
 楼主| 发表于 2014-2-16 19:47:15 | 显示全部楼层
站长苏飞 发表于 2014-2-16 18:58
那就使用登录页面的cookie获取验证码,然后登录

不行,我就是用的登录页面的cooike,去注册post的。
发现注册页面,有2个跨域的url,是随着验证码一起的,就是验证码一刷新,就会多2个url出来,而且有cooike返回来,不过那2个url的请求相关的js太复杂了
发表于 2014-3-6 11:13:54 | 显示全部楼层
zbsgift 发表于 2014-2-16 19:47
不行,我就是用的登录页面的cooike,去注册post的。
发现注册页面,有2个跨域的url,是随着验证码一起的 ...

我也遇到这个问题了,楼主解决了吗????????、
您需要登录后才可以回帖 登录 | 马上注册

本版积分规则

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

GMT+8, 2024-6-1 17:15

© 2014-2021

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