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

苏飞论坛

 找回密码
 马上注册

QQ登录

只需一步,快速开始

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

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

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

查看: 3047|回复: 5

[其他] C#Httphelper自动登陆爱站一直登陆不上去,苏飞老大帮忙看看

[复制链接]
发表于 2013-7-25 11:50:58 | 显示全部楼层 |阅读模式
附件代码!

登陆爱站网.zip

69.69 KB, 下载次数: 152, 下载积分: 金钱 -1



1. 开通SVIP会员,免费下载本站所有源码,不限次数据,不限时间
2. 加官方QQ群,加官方微信群获取更多资源和帮助
3. 找站长苏飞做网站、商城、CRM、小程序、App、爬虫相关、项目外包等点这里
发表于 2013-7-25 12:02:33 | 显示全部楼层
贴下代码白,还得下载有点懒{:soso_e128:}
 楼主| 发表于 2013-7-25 12:18:10 | 显示全部楼层
yangying 发表于 2013-7-25 12:02
贴下代码白,还得下载有点懒

  HttpHelper http = new HttpHelper();
            HttpItem item = new HttpItem()
            {
                URL = "http://www.aizhan.com/login.php",//URL这里都是测试URl   必需项
                //Encoding = null,//编码格式(utf-8,gb2312,gbk)     可选项 默认类会自动识别
                Encoding = Encoding.UTF8,
                Method = "post",//URL     可选项 默认为Get
                ContentType = "application/x-www-form-urlencoded",
                Postdata = "refer=&email=328666469@qq.com&password=jiahonglin"
            };

            //得到HTML代码
            HttpResult result = http.GetHtml(item);
            http = new HttpHelper();
            item = new HttpItem()
            {
                URL = "http://www.aizhan.com/user.php",//URL这里都是测试URl   必需项
                //Encoding = null,//编码格式(utf-8,gb2312,gbk)     可选项 默认类会自动识别
                Encoding = Encoding.Default,
                Method = "get",//URL     可选项 默认为Get
                Cookie = result.Cookie
            };

            //得到HTML代码
            result = http.GetHtml(item);
            richTextBox1.Text = result.Html;
        }

代码!

发表于 2013-7-25 13:14:13 | 显示全部楼层
[code=csharp]            HttpHelper http = new HttpHelper();
            HttpItem item = new HttpItem()
           {
               URL = "http://www.aizhan.com/login.php",//URL这里都是测试URl   必需项
               Method = "post",//URL     可选项 默认为Get
               ContentType = "application/x-www-form-urlencoded",
               Postdata = "refer=&email=328666469@qq.com&password=jiahonglin",
           };

            //得到HTML代码
            HttpResult result = http.GetHtml(item);
            //生成Cookie
            string scookie = HttpCookieHelper.CookieFormat("PHPSESSID", HttpCookieHelper.GetCookieValue("PHPSESSID", result.Cookie));
            scookie += HttpCookieHelper.CookieFormat("userId", HttpCookieHelper.GetCookieValue("userId", result.Cookie));
            scookie += HttpCookieHelper.CookieFormat("userName", HttpCookieHelper.GetCookieValue("userName", result.Cookie));
            scookie += HttpCookieHelper.CookieFormat("userGroup", HttpCookieHelper.GetCookieValue("userGroup", result.Cookie));
            scookie += HttpCookieHelper.CookieFormat("userSecure", HttpCookieHelper.GetCookieValue("userSecure", result.Cookie));
            item = new HttpItem()
            {
                URL = "http://www.aizhan.com/user.php",//URL这里都是测试URl   必需项
                Cookie = scookie
            };

            //得到HTML代码
            result = http.GetHtml(item);
            richTextBox1.Text = result.Html;[/code]
HttpCookieHelper在Httphelper的下载处有下载,可以使用这个类进行Cookie格式化就行了。
发表于 2013-7-25 13:22:15 | 显示全部楼层
xwjcs 发表于 2013-7-25 12:18
HttpHelper http = new HttpHelper();
            HttpItem item = new HttpItem()
            {

cookie = result.Cookie.Replace("path=/,", "").Replace(",", ";");// 去掉cookie中的 path=/,  并替换逗号为分号
 楼主| 发表于 2013-7-25 15:35:40 | 显示全部楼层
谢谢老大,谢谢各位捧场的朋友!十分感谢!
您需要登录后才可以回帖 登录 | 马上注册

本版积分规则

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

GMT+8, 2024-5-17 11:26

© 2014-2021

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