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

苏飞论坛

 找回密码
 马上注册

QQ登录

只需一步,快速开始

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

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

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

查看: 610672|回复: 317
打印 上一主题 下一主题

[发布] [C#HttpHelper]官方产品发布与源码下载---苏飞版

   关闭 [复制链接]
跳转到指定楼层
发表于 2012-6-30 13:16:00 | 只看该作者 |只看大图 回帖奖励 |正序浏览 |阅读模式
                             C#HttpHelper官方产品发布与源码下载---苏飞版
导读部分
-------------------------------------------------------------------------------------------------------------
C#基类库苏飞版--系列教程导航
http://www.sufeinet.com/thread-655-1-1.html

                      本站是C#HttpHelper类官方网站,唯一更新网站,希望大家收藏关注。
介绍
      C#HttpHelper实现了C#HttpWebRequest抓取时无视编码,绕过证书,无视Cookie,并且实现的代理的功能,使用它您可以进行Get和Post请求,可以很方便 的设置Cookie证书代理编码问题您不用管,因为类会自动为您识别网页的编码。
       这个类是我以前写百度,Google,Soso,Sogou等网络蜘蛛时使用的,经过上千万个网站的测试,上万个网站抓取的例子总结出来的,中间的方法也是我实验了很久之后方案,所以大家可以放心使用。

        我不敢说100%,但是应该是99%的网站都没有问题,都可以无视编码,证书,和Cookie,如果你确实发现那个网站在使用本类过程中有问题,出现乱码,或者是获取不了,不能带Cookie,不能带证书等问题,我非常乐意您能联系我,提出您的问题,您也可以直接回复本帖子,我会第一时间进行解答。
   
本类永久开源免费,爬虫框架,只是使用Httphelper类写出来的一个作品,和类本身没有关系,大家不会误会哦! Httphelper类是免费的,收费的是使用Httphelper类写出的万能框架!

Httphelper代码在线预览


购买类库版(爬虫框架),功能强大10倍http://httphelper.sufeinet.com/

1.HttpHelper类下载




代码生成器:http://www.sufeinet.com/thread-3690-1-1.html   如果你不会使用类可以使用这个工具直接生成访问代码,非常方便
下载之前你首先要注册成为会员哦,注册之后就可以直接下载啦
以下是各个版本的HttpHelper类下载链接
以后HttpHelper类就不再提供多个版本了,只提供最新的Net2.0和4.0版本的。当然也有可能提供3.5或者是更高版本的,而不是像现在提供多个版本类,只对Net版本进行开发。希望大家喜欢
我相信这样功能会更全面一些。

最新版本下载

注意哦,如果不是本站注册会员是没有权限下载的
HttpHelpe-V2.3.7.zip (6.73 KB, 下载次数: 413)
   支持.netcore版本,可以直接引用
  1. 本版本是Net4.0的第一个版本,功能远远超过2.0,并且使用最新最潮的技术,从性能和稳定性上有质的飞越
复制代码

关键我的抖音号了解更多:



历史版本:
HttpHelperV2.3.6.zip (6.62 KB, 下载次数: 279)
HttpHelper_CoreV2.1.zip (6.54 KB, 下载次数: 335)
HttpHelperV2.3.zip (6.61 KB, 下载次数: 397)
HttpHelper-V2.2.9.zip (6.62 KB, 下载次数: 1181)
HttpHelperV20.0.7.zip (6.54 KB, 下载次数: 333)
HttpHelperV2.0.2.zip (6.54 KB, 下载次数: 556)
HttpHelperV2.0.1.zip (6.54 KB, 下载次数: 265)

HttpHelperV1.9.1.rar (6.4 KB, 下载次数: 2010)
HttpHelperV1.9.rar (6.4 KB, 下载次数: 4618)
HttpHelperV1.9.rar (6.4 KB, 下载次数: 1380)
HttpHelperV1.8-Net4.0版本.zip (6.38 KB, 下载次数: 3437)
HttpHelper_4.0.zip (6.37 KB, 下载次数: 106165)
.Net2.0版本
HttpHelper_2.0.rar (6.67 KB, 下载次数: 153620)
HttpHelperV1.8-Net2.0版.zip (6.72 KB, 下载次数: 3332)

相关链接


Httphelper类源码下载:http://www.sufeinet.com/thread-3-1-1.html
Httphelper类在线代码生成器:http://www.sufeinet.com/thread-3690-1-1.html
Httphelper类原理http://www.sufeinet.com/thread-6-1-1.html
Httphelper类教程:http://www.sufeinet.com/forum.ph ... action=view&ctid=23
Httphelper类例子:http://www.sufeinet.com/forum.ph ... action=view&ctid=22
HttpCookieHelper帮助类:http://www.sufeinet.com/thread-2382-1-1.html

Httphelper头信息(ContentType)默认为text/html无懈可击

2.在webBrowser中取Cookie的方法

在很多情况下我们会使用间进程的webBrowser去实现一些网页的请求和抓去,这个时候有部分网页是取不到Cookie的,那怎么办呢?下面我提供一个方法,应该99%的都能取到,
[C#] 纯文本查看 复制代码
//取当前webBrowser登录后的Cookie值   
        [DllImport("wininet.dll", CharSet = CharSet.Auto, SetLastError = true)]
        static extern bool InternetGetCookieEx(string pchURL, string pchCookieName, StringBuilder pchCookieData, ref int pcchCookieData, int dwFlags, object lpReserved);
        //取出Cookie,当登录后才能取    
        private static string GetCookieString(string url)
        {
            // Determine the size of the cookie      
            int datasize = 256;
            StringBuilder cookieData = new StringBuilder(datasize);
            if (!InternetGetCookieEx(url, null, cookieData, ref datasize, 0x00002000, null))
            {
                if (datasize < 0)
                    return null;
                // Allocate stringbuilder large enough to hold the cookie    
                cookieData = new StringBuilder(datasize);
                if (!InternetGetCookieEx(url, null, cookieData, ref datasize, 0x00002000, null))
                    return null;
            }
            return cookieData.ToString();
        }

3.去掉所有的Html代码

[C#] 纯文本查看 复制代码
/// <summary>
        /// 过滤html标签
        /// </summary>
        /// <param name="strHtml">html的内容</param>
        /// <returns></returns>
        public static string StripHTML(string stringToStrip)
        {
            // paring using RegEx           //
            stringToStrip = Regex.Replace(stringToStrip, "</p(?:\\s*)>(?:\\s*)<p(?:\\s*)>", "\n\n", RegexOptions.IgnoreCase | RegexOptions.Compiled);
            stringToStrip = Regex.Replace(stringToStrip, "", "\n", RegexOptions.IgnoreCase | RegexOptions.Compiled);
            stringToStrip = Regex.Replace(stringToStrip, "\"", "''", RegexOptions.IgnoreCase | RegexOptions.Compiled);
            stringToStrip = StripHtmlXmlTags(stringToStrip);
            return stringToStrip;
        }
        private static string StripHtmlXmlTags(string content)
        {
            return Regex.Replace(content, "<[^>]+>", "", RegexOptions.IgnoreCase | RegexOptions.Compiled);
        }

方法如上面所示直接调用StripHTML方法就行了
4.设置URl格式的问题

[C#] 纯文本查看 复制代码
 public static string URLDecode(string text)
        {
            return HttpUtility.UrlDecode(text, Encoding.Default);
        }
        public static string URLEncode(string text)
        {
            return HttpUtility.UrlEncode(text, Encoding.Default);
        }

5.HttpHelper类使用方法

使用方法如下
[C#] 纯文本查看 复制代码
HttpHelper http = new HttpHelper();
            HttpItem item = new HttpItem()
            {
                URL = "http://www.sufeinet.com",//URL     必需项
                Encoding = null,//编码格式(utf-8,gb2312,gbk)     可选项 默认类会自动识别
                //Encoding = Encoding.Default,
                Method = "get",//URL     可选项 默认为Get
                Timeout = 100000,//连接超时时间     可选项默认为100000
                ReadWriteTimeout = 30000,//写入Post数据超时时间     可选项默认为30000
                IsToLower = false,//得到的HTML代码是否转成小写     可选项默认转小写
                Cookie = "",//字符串Cookie     可选项
                UserAgent = "Mozilla/5.0 (compatible; MSIE 9.0; Windows NT 6.1; Trident/5.0)",//用户的浏览器类型,版本,操作系统     可选项有默认值
                Accept = "text/html, application/xhtml+xml, */*",//    可选项有默认值
                ContentType = "text/html",//返回类型    可选项有默认值
                Referer = "http://www.sufeinet.com",//来源URL     可选项
                Allowautoredirect = true,//是否根据301跳转     可选项
                CerPath = "d:\\123.cer",//证书绝对路径     可选项不需要证书时可以不写这个参数
                Connectionlimit = 1024,//最大连接数     可选项 默认为1024
                Postdata = "C:\\PERKYSU_20121129150608_ScrubLog.txt",//Post数据     可选项GET时不需要写
                PostDataType = PostDataType.FilePath,//默认为传入String类型,也可以设置PostDataType.Byte传入Byte类型数据
                ProxyIp = "192.168.1.105:8015",//代理服务器ID 端口可以直接加到后面以:分开就行了    可选项 不需要代理 时可以不设置这三个参数
                ProxyPwd = "123456",//代理服务器密码     可选项
                ProxyUserName = "administrator",//代理服务器账户名     可选项
                ResultType = ResultType.Byte,//返回数据类型,是Byte还是String
                PostdataByte = System.Text.Encoding.Default.GetBytes("测试一下"),//如果PostDataType为Byte时要设置本属性的值
                CookieCollection = new System.Net.CookieCollection(),//可以直接传一个Cookie集合进来
            };
            item.Header.Add("测试Key1", "测试Value1");
            item.Header.Add("测试Key2", "测试Value2");
            //得到HTML代码
            HttpResult result = http.GetHtml(item);
            //取出返回的Cookie
            string cookie = result.Cookie;
            //返回的Html内容
            string html = result.Html;
            if (result.StatusCode == System.Net.HttpStatusCode.OK)
            {
                //表示访问成功,具体的大家就参考HttpStatusCode类
            }
            //表示StatusCode的文字说明与描述
            string statusCodeDescription = result.StatusDescription;
            //把得到的Byte转成图片
            Image img = byteArrayToImage(result.ResultByte);
        }
        /// <summary>
        /// 字节数组生成图片
        /// </summary>
        /// <param name="Bytes">字节数组</param>
        /// <returns>图片</returns>
   private Image byteArrayToImage(byte[] Bytes)
        {
                MemoryStream ms = new MemoryStream(Bytes);
                Image outputImg = Image.FromStream(ms);
                return outputImg;
        }}

本例子是一个统一的标准写法,大家可以根据需要自行修改,在下面还会有对特定功能的说明请大家继续看
6.最简单的Post与Get的写法

[C#] 纯文本查看 复制代码
 HttpHelper http = new HttpHelper();
            HttpItem item = new HttpItem()
            {
                URL = "http://www.sufeinet.com",//URL这里都是测试     必需项
                Method = "get",//URL     可选项 默认为Get
            };
            //得到HTML代码
            HttpResult result = http.GetHtml(item);
            item = new HttpItem()
           {
               URL = "http://tool.sufeinet.com",//URL这里都是测试URl   必需项
               Encoding = null,//编码格式(utf-8,gb2312,gbk)     可选项 默认类会自动识别
               //Encoding = Encoding.Default,
               Method = "post",//URL     可选项 默认为Get
               Postdata = "user=123123&pwd=1231313"
           };
            //得到新的HTML代码
            result = http.GetHtml(item);

7.HttpHelper设置Header参考的方法

[C#] 纯文本查看 复制代码
  HttpHelper http = new HttpHelper();
            HttpItem item = new HttpItem()
            {
                URL = "http://www.sufeinet.com",//URL     必需项
                Encoding = null,//编码格式(utf-8,gb2312,gbk)     可选项 默认类会自动识别
                 //Encoding = Encoding.Default,
                Method = "get",//URL     可选项 默认为Get
            };
            item.Header.Add("测试Key1", "测试Value1");
            item.Header.Add("测试Key2", "测试Value2");
            //得到HTML代码
            HttpResult result = http.GetHtml(item);
            //取出返回的Cookie
            string cookie = result.Cookie;
            //返回的Html内容
            string html = result.Html;
            if (result.StatusCode == System.Net.HttpStatusCode.OK)
            {
                //表示访问成功,具体的大家就参考HttpStatusCode类
            }
            //表示StatusCode的文字说明与描述
            string statusCodeDescription = result.StatusDescription;



下面我列出一些不能直接Add的参数
8.HttpHelper获取图片的方式
[C#] 纯文本查看 复制代码
  HttpHelper http = new HttpHelper();
            HttpItem item = new HttpItem()
            {
                URL = "http://www.sufeinet.com",//URL     必需项
                Encoding = null,//编码格式(utf-8,gb2312,gbk)     可选项 默认类会自动识别
                //Encoding = Encoding.Default,
                ResultType = ResultType.Byte
            };
            //得到HTML代码
            HttpResult result = http.GetHtml(item);
            if (result.StatusCode == System.Net.HttpStatusCode.OK)
            {
                //表示访问成功,具体的大家就参考HttpStatusCode类
            }
            //表示StatusCode的文字说明与描述
            string statusCodeDescription = result.StatusDescription;
            //把得到的Byte转成图片
            Image img = byteArrayToImage(result.ResultByte);
        }

        /// <summary>
        /// 字节数组生成图片
        /// </summary>
        /// <param name="Bytes">字节数组</param>
        /// <returns>图片</returns>
        private Image byteArrayToImage(byte[] Bytes)
        {
                MemoryStream ms = new MemoryStream(Bytes);
                Image outputImg = Image.FromStream(ms);
                return outputImg;
        }

9.二次或多次使用Cookie的方式

字符串Cookie
[C#] 纯文本查看 复制代码
  HttpHelper http = new HttpHelper();
            HttpItem item = new HttpItem()
            {
                URL = "http://www.sufeinet.com",//URL这里都是测试     必需项
                Encoding = null,//编码格式(utf-8,gb2312,gbk)     可选项 默认类会自动识别
                //Encoding = Encoding.Default,
                Method = "get",//URL     可选项 默认为Get
            };
            //得到HTML代码
            HttpResult result = http.GetHtml(item);
            item = new HttpItem()
           {
               URL = "http://tool.sufeinet.com",//URL这里都是测试URl   必需项
               Encoding = null,//编码格式(utf-8,gb2312,gbk)     可选项 默认类会自动识别
               //Encoding = Encoding.Default,
               Method = "get",//URL     可选项 默认为Get
               Cookie = result.Cookie,
           };
            //得到新的HTML代码
            result = http.GetHtml(item);

CookieCollection类型的Cookie使用方法
[C#] 纯文本查看 复制代码
 HttpHelper http = new HttpHelper();
            HttpItem item = new HttpItem()
            {
                URL = "http://www.sufeinet.com",//URL这里都是测试     必需项
                Encoding = null,//编码格式(utf-8,gb2312,gbk)     可选项 默认类会自动识别
                //Encoding = Encoding.Default,
                Method = "get",//URL     可选项 默认为Get
                ResultCookieType = ResultCookieType.CookieCollection
            };
            //得到HTML代码
            HttpResult result = http.GetHtml(item);
            item = new HttpItem()
            {
                URL = "http://tool.sufeinet.com",//URL这里都是测试URl   必需项
                Encoding = null,//编码格式(utf-8,gb2312,gbk)     可选项 默认类会自动识别
                //Encoding = Encoding.Default,
                Method = "get",//URL     可选项 默认为Get
                CookieCollection = result.CookieCollection,
                ResultCookieType = ResultCookieType.CookieCollection
            };
            //得到新的HTML代码
            result = http.GetHtml(item);


10.以下是对本类提出过建议或者是有杰出贡献的用户
------------------------------------------------------------用户列表--------------------------------------------------------------------------------
myde520               xlj_qq                        xiaotianbao                        Eagle                          changlei                           kidsoft
ReEnter                 cyberarmy                  cyberarmy                        依然在飞翔                 Kiiilo                                 Monn
小小程序员           aspirer











HttpHelperV20.0.9.zip

6.62 KB, 下载次数: 1663, 下载积分: 金钱 -1

HttpHelper-V2.2.97.zip

6.62 KB, 下载次数: 1542, 下载积分: 金钱 -1

HttpHelperV2.3.5.zip

6.62 KB, 下载次数: 278, 下载积分: 金钱 -1

本帖被以下淘专辑推荐:



1. 开通SVIP会员,免费下载本站所有源码,不限次数据,不限时间
2. 加官方QQ群,加官方微信群获取更多资源和帮助
3. 找站长苏飞做网站、商城、CRM、小程序、App、爬虫相关、项目外包等点这里
推荐
 楼主| 发表于 2016-5-5 15:48:05 | 只看该作者
V1.6版已更新,修复N多Bug
308
 楼主| 发表于 2022-12-1 18:37:43 | 只看该作者
v2.3.5发布更新了已知Bug
307
 楼主| 发表于 2022-6-9 08:41:06 | 只看该作者

V2.3.5版已更新,修复部分Bug
306
 楼主| 发表于 2019-4-23 11:09:14 | 只看该作者
v2.0.2更新 修复Gzip和乱码的问题
305
 楼主| 发表于 2019-3-27 14:16:35 | 只看该作者
更新了近期收集到的Bug
304
 楼主| 发表于 2019-3-27 14:16:24 | 只看该作者
更新了近期收集到的Bug
303
 楼主| 发表于 2018-11-27 14:44:28 | 只看该作者
1.9.9版本更新,主要优化了对Cookie的处理方式
302
 楼主| 发表于 2018-11-26 18:32:40 | 只看该作者
QQ的订阅邮件无法使用了,大家不要再订阅了。
301
 楼主| 发表于 2017-1-16 11:25:57 | 只看该作者
HtttphelperV1.8版本正式发布
http://www.sufeinet.com/thread-18067-1-1.html
(出处: 苏飞论坛)
300
 楼主| 发表于 2016-12-5 09:15:13 | 只看该作者
2016-12-05更新到V1.7

1.修复301跳转值
2.修复部分默认参数
您需要登录后才可以回帖 登录 | 马上注册

本版积分规则

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

GMT+8, 2024-5-14 16:55

© 2014-2021

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