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

苏飞论坛

 找回密码
 马上注册

QQ登录

只需一步,快速开始

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

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

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

查看: 14213|回复: 18

[求助] 求助!登陆成功AJAX操作添加好友问题

[复制链接]
发表于 2013-6-3 10:17:01 | 显示全部楼层 |阅读模式
感谢飞哥解决了登陆问题,不知道是不是抓取数据出错了,还要请教一下飞哥登陆成功后添加好友的问题。
登陆成功例子在这个帖子:
http://www.sufeinet.com/thread-3464-1-1.html

而直接在地址栏输入:http://www.loveq.cn/friend.php?act=add&uid=235214&is_ajax=1
添加提示成功。


[code=csharp]            //登录成功后进行添加好友操作
            item = new HttpItem()
            {
                URL = "http://www.loveq.cn/friend.php",//URL      
                Method = "POST",//URL     可选项 默认为Get
               
                Cookie = result.Cookie,//当前登录Cookie
                Postdata = "act=add&uid=235214&is_ajax=1"  //POST出去的数据,添加好友,httpwatch抓取,不知道对不对?

            result = http.GetHtml(item);
            string html = result.Html;
            string cookie = result.Cookie.ToString();
            textBox1.AppendText(html);// 添加成功返回:{"error":0,"message":"\u6dfb\u52a0\u597d\u53cb\u6210\u529f\uff01","content":""}            添加失败返回:cookies:{"error":1,"message":"Ta \u5df2\u7ecf\u5728\u4f60\u7684\u597d\u53cb\u5217\u8868\u4e2d\u4e86\uff01","content":""}
            };[/code]

本帖被以下淘专辑推荐:



1. 开通SVIP会员,免费下载本站所有源码,不限次数据,不限时间
2. 加官方QQ群,加官方微信群获取更多资源和帮助
3. 找站长苏飞做网站、商城、CRM、小程序、App、爬虫相关、项目外包等点这里
发表于 2013-6-3 10:41:42 | 显示全部楼层
[code=csharp]
            HttpHelper http = new HttpHelper();
            HttpItem item = new HttpItem()
            {
                URL = "http://www.loveq.cn/user.php",//URL     必需项  
                Method = "POST",//URL     可选项 默认为Get  
                Timeout = 100000,//连接超时时间     可选项默认为100000  
                ReadWriteTimeout = 30000,//写入Post数据超时时间     可选项默认为30000  
                IsToLower = false,//得到的HTML代码是否转成小写     可选项默认转小写  
                Referer = "http://www.loveq.cn/user-default.html",
                ContentType = "application/x-www-form-urlencoded",//返回类型    可选项有默认值  
                Postdata = "username=test00001&password=test00001&act=act_login&back_act=user.php%3Fact%3Ddefault",//Post数据     可选项GET时不需要写  
                //Allowautoredirect = false
            };
            HttpResult result = http.GetHtml(item);
            //登录成功后进行添加好友操作
            item = new HttpItem()
            {
                URL = "http://www.loveq.cn/friend.php",//URL      
                Method = "POST",//URL     可选项 默认为Get
                Cookie = result.Cookie,//当前登录Cookie
                Postdata = "act=add&uid=1035182&is_ajax=1", //POST出去的数据,添加好友,httpwatch抓取,不知道对不对?
                ContentType = "application/x-www-form-urlencoded",
                Referer = "http://www.loveq.cn/user_list.php?sex=1&age[0]=&age[1]=&height[0]=&height[1]=&weight[0]=&weight[1]=&residence[c]=1&residence[p]=0&residence[t]=0&residence[d]=0&photo=0&order=post&act=act_search&fromact=quick"
            };
            item.Cookie = item.Cookie.Replace("path=/;","");
            item.Header.Add("X-Requested-With", "XMLHttpRequest");
            item.Header.Add("Powered-By", "Ican Cheung");
            result = http.GetHtml(item);
            string html = result.Html;[/code]

 楼主| 发表于 2013-6-3 11:03:30 | 显示全部楼层

测试了一下还是返回: {"error":1,"message":"Ta \u5df2\u7ecf\u5728\u4f60\u7684\u597d\u53cb\u5217\u8868\u4e2d\u4e86\uff01","content":""}

好像还有一点问题。。
发表于 2013-6-3 11:06:40 | 显示全部楼层
猫星人 发表于 2013-6-3 11:03
测试了一下还是返回: {"error":1,"message":"Ta \u5df2\u7ecf\u5728\u4f60\u7684\u597d\u53cb\u5217\u88 ...

这个你再好好看看代码吧,我测试过是正常的,
 楼主| 发表于 2013-6-3 22:55:20 | 显示全部楼层
还是不行哦,是不是64位系统有影响?都是返回。[code=csharp]{"error":1,"message":"\u5c0a\u8d35\u7684\u7528\u6237\uff0c\u60a8\u8fd8\u6ca1\u6709\u767b\u5f55\u3002\u5fc5\u987b\u767b\u5f55\u624d\u80fd\u5b8c\u6210\u64cd\u4f5c\u3002","content":"","url":"\/user-login.html"}[/code]
发表于 2013-6-4 08:10:43 | 显示全部楼层
最后是Ajax问题,此问题已解决了
 楼主| 发表于 2013-6-6 17:58:04 | 显示全部楼层
发现是 UserAgent 问题,有待修改。不知道我的UserAgent 需要怎么写?

问题跟这个帖子一样:
http://www.sufeinet.com/forum.php?mod=viewthread&tid=3507
发表于 2013-6-6 18:00:45 | 显示全部楼层
猫星人 发表于 2013-6-6 17:58
发现是 UserAgent 问题,有待修改。不知道我的UserAgent 需要怎么写?

问题跟这个帖子一样:

抓包看看,包里面是什么就写什么就行了
 楼主| 发表于 2013-6-7 13:02:50 | 显示全部楼层
本帖最后由 猫星人 于 2013-6-7 13:10 编辑
yangying 发表于 2013-6-6 18:00
抓包看看,包里面是什么就写什么就行了

抓到的:UserAgent = "Mozilla/5.0 (compatible; MSIE 9.0; Windows NT 6.1; WOW64; Trident/5.0)",

不过好像不是这个问题,加上这个还是不行。


添加好友还是失败呢。这里是打包的代码:http://pan.baidu.com/share/link?shareid=1145312664&uk=4227909875
发表于 2013-6-7 14:06:43 | 显示全部楼层
猫星人 发表于 2013-6-7 13:02
抓到的:UserAgent = "Mozilla/5.0 (compatible; MSIE 9.0; Windows NT 6.1; WOW64; Trident/5.0)",

...

2楼站长的代码是对的呀,我测试过,是正常的,你再看看吧
您需要登录后才可以回帖 登录 | 马上注册

本版积分规则

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

GMT+8, 2024-5-3 11:47

© 2014-2021

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