ASP.NET(C#)经典采集代码
using System;
 using System.Data;
using System.Data;
 using System.Configuration;
using System.Configuration;
 using System.Web;
using System.Web;
 using System.Web.Security;
using System.Web.Security;
 using System.Web.UI;
using System.Web.UI;
 using System.Web.UI.WebControls;
using System.Web.UI.WebControls;
 using System.Web.UI.WebControls.WebParts;
using System.Web.UI.WebControls.WebParts;
 using System.Web.UI.HtmlControls;
using System.Web.UI.HtmlControls;
 using System.Drawing;
using System.Drawing;
 using MSXML2;
using MSXML2;
 using System.Text.RegularExpressions;
using System.Text.RegularExpressions;
 namespace wenweifeng
namespace wenweifeng


 {
{

 /**//// <summary>
    /**//// <summary>
 /// CaiJi 的摘要说明
    /// CaiJi 的摘要说明
 /// </summary>
    /// </summary>
 public class CaiJi
    public class CaiJi

 
     {
{
 public CaiJi()
        public CaiJi()

 
         {
{
 //
            //
 // TODO: 在此处添加构造函数逻辑
            // TODO: 在此处添加构造函数逻辑
 //
            //
 }
        }
 ~CaiJi()
        ~CaiJi()

 
         {
{
 Dispose();
            Dispose();
 }
        }
 public void Dispose()
        public void Dispose()

 
         {
{
 GC.SuppressFinalize(this);
         GC.SuppressFinalize(this);
 }
        }
 
  

 日期随机函数#region 日期随机函数
     日期随机函数#region 日期随机函数

 /**//**********************************
        /**//**********************************
 * 函数名称:DateRndName
         * 函数名称:DateRndName
 * 功能说明:日期随机函数
         * 功能说明:日期随机函数
 * 参    数:ra:随机数
         * 参    数:ra:随机数
 * 调用示例:
         * 调用示例:
 *          GetRemoteObj o = new GetRemoteObj();
         *          GetRemoteObj o = new GetRemoteObj();
 *          Random ra = new Random();
         *          Random ra = new Random();
 *          string s = o.DateRndName(ra);
         *          string s = o.DateRndName(ra);
 *          Response.Write(s);
         *          Response.Write(s);
 *          o.Dispose();
         *          o.Dispose();
 * ********************************/
         * ********************************/

 /**//// <summary>
        /**//// <summary>
 /// 日期随机函数
        /// 日期随机函数
 /// </summary>
        /// </summary>
 /// <param name="ra">随机数</param>
        /// <param name="ra">随机数</param>
 /// <returns></returns>
        /// <returns></returns>
 public  string DateRndName(Random ra)
        public  string DateRndName(Random ra)

 
         {
{
 DateTime d = DateTime.Now;
            DateTime d = DateTime.Now;
 string s = null, y, m, dd, h, mm, ss;
            string s = null, y, m, dd, h, mm, ss;
 y = d.Year.ToString();
            y = d.Year.ToString();
 m = d.Month.ToString();
            m = d.Month.ToString();
 if (m.Length < 2) m = "0" + m;
            if (m.Length < 2) m = "0" + m;
 dd = d.Day.ToString();
            dd = d.Day.ToString();
 if (dd.Length < 2) dd = "0" + dd;
            if (dd.Length < 2) dd = "0" + dd;
 h = d.Hour.ToString();
            h = d.Hour.ToString();
 if (h.Length < 2) h = "0" + h;
            if (h.Length < 2) h = "0" + h;
 mm = d.Minute.ToString();
            mm = d.Minute.ToString();
 if (mm.Length < 2) mm = "0" + mm;
            if (mm.Length < 2) mm = "0" + mm;
 ss = d.Second.ToString();
            ss = d.Second.ToString();
 if (ss.Length < 2) ss = "0" + ss;
            if (ss.Length < 2) ss = "0" + ss;
 s += y + ',' + m + ',' + dd + ',' + h + "-" + mm + "-" + ss;
            s += y + ',' + m + ',' + dd + ',' + h + "-" + mm + "-" + ss;
 s += ra.Next(1000000, 9999999).ToString();
            s += ra.Next(1000000, 9999999).ToString();
 return s;
            return s;
 }
        }
 #endregion
        #endregion


 取得文件后缀#region 取得文件后缀
        取得文件后缀#region 取得文件后缀

 /**//**********************************
        /**//**********************************
 * 函数名称:GetFileExtends
         * 函数名称:GetFileExtends
 * 功能说明:取得文件后缀
         * 功能说明:取得文件后缀
 * 参    数:filename:文件名称
         * 参    数:filename:文件名称
 * 调用示例:
         * 调用示例:
 *          GetRemoteObj o = new GetRemoteObj();
         *          GetRemoteObj o = new GetRemoteObj();
 *          string url = @"http://www.baidu.com/img/logo.gif";
         *          string url = @"http://www.baidu.com/img/logo.gif";
 *          string s = o.GetFileExtends(url);
         *          string s = o.GetFileExtends(url);
 *          Response.Write(s);
         *          Response.Write(s);
 *          o.Dispose();
         *          o.Dispose();
 * ********************************/
         * ********************************/

 /**//// <summary>
        /**//// <summary>
 /// 取得文件后缀
        /// 取得文件后缀
 /// </summary>
        /// </summary>
 /// <param name="filename">文件名称</param>
        /// <param name="filename">文件名称</param>
 /// <returns></returns>
        /// <returns></returns>
 public string GetFileExtends(string filename)
        public string GetFileExtends(string filename)

 
         {
{
 string ext = null;
            string ext = null;
 if (filename.IndexOf('.') > 0)
            if (filename.IndexOf('.') > 0)

 
             {
{
 string[] fs = filename.Split('.');
                string[] fs = filename.Split('.');
 ext = fs[fs.Length - 1];
                ext = fs[fs.Length - 1];
 }
            }
 return ext;
            return ext;
 }
        }
 #endregion
        #endregion


 获取远程文件源代码#region 获取远程文件源代码
        获取远程文件源代码#region 获取远程文件源代码

 /**//**********************************
        /**//**********************************
 * 函数名称:GetRemoteHtmlCode
         * 函数名称:GetRemoteHtmlCode
 * 功能说明:获取远程文件源代码
         * 功能说明:获取远程文件源代码
 * 参    数:Url:远程url
         * 参    数:Url:远程url
 * 调用示例:
         * 调用示例:
 *          GetRemoteObj o = new GetRemoteObj();
         *          GetRemoteObj o = new GetRemoteObj();
 *          string url = @"http://www.baidu.com";
         *          string url = @"http://www.baidu.com";
 *          string s = o.GetRemoteHtmlCode(url);
         *          string s = o.GetRemoteHtmlCode(url);
 *          Response.Write(s);
         *          Response.Write(s);
 *          o.Dispose();
         *          o.Dispose();
 * ********************************/
         * ********************************/

 /**//// <summary>
        /**//// <summary>
 /// 获取远程文件源代码
        /// 获取远程文件源代码
 /// </summary>
        /// </summary>
 /// <param name="url">远程url</param>
        /// <param name="url">远程url</param>
 /// <returns></returns>
        /// <returns></returns>
 public string GetRemoteHtmlCode(string Url)
        public string GetRemoteHtmlCode(string Url)

 
         {
{
 string s = "";
            string s = "";
 MSXML2.XMLHTTP _xmlhttp = new MSXML2.XMLHTTPClass();
            MSXML2.XMLHTTP _xmlhttp = new MSXML2.XMLHTTPClass();
 _xmlhttp.open("GET", Url, false, null, null);
            _xmlhttp.open("GET", Url, false, null, null);
 _xmlhttp.send("");
            _xmlhttp.send("");
 if (_xmlhttp.readyState == 4)
            if (_xmlhttp.readyState == 4)

 
             {
{
 s = System.Text.Encoding.Default.GetString((byte[])_xmlhttp.responseBody);
                s = System.Text.Encoding.Default.GetString((byte[])_xmlhttp.responseBody);
 }
            }
 return s;
            return s;
 }
        }

 #endregion
        #endregion


 保存远程文件#region 保存远程文件
        保存远程文件#region 保存远程文件

 /**//**********************************
        /**//**********************************
 * 函数名称:RemoteSave
         * 函数名称:RemoteSave
 * 功能说明:保存远程文件
         * 功能说明:保存远程文件
 * 参    数:Url:远程url;Path:保存到的路径
         * 参    数:Url:远程url;Path:保存到的路径
 * 调用示例:
         * 调用示例:
 *          GetRemoteObj o = new GetRemoteObj();
         *          GetRemoteObj o = new GetRemoteObj();
 *          string s = "";
         *          string s = "";
 *          string url = @"http://www.baidu.com/img/logo.gif";
         *          string url = @"http://www.baidu.com/img/logo.gif";
 *          string path =Server.MapPath("Html/");
         *          string path =Server.MapPath("Html/");
 *          s = o.RemoteSave(url,path);
         *          s = o.RemoteSave(url,path);
 *          Response.Write(s);
         *          Response.Write(s);
 *          o.Dispose();
         *          o.Dispose();         
 * ******************************/
         * ******************************/

 /**//// <summary>
        /**//// <summary>
 /// 保存远程文件
        /// 保存远程文件
 /// </summary>
        /// </summary>
 /// <param name="Url">远程url</param>
        /// <param name="Url">远程url</param>
 /// <param name="Path">保存到的路径</param>
        /// <param name="Path">保存到的路径</param>
 /// <returns></returns>
        /// <returns></returns>
 public string RemoteSave(string Url, string Path)
        public string RemoteSave(string Url, string Path)

 
         {
{
 
         
 Random ra = new Random();
            Random ra = new Random();
 string newfilename = string.Empty;
            string newfilename = string.Empty;
 string StringFileName = DateRndName(ra) + "." + GetFileExtends(Url);
            string StringFileName = DateRndName(ra) + "." + GetFileExtends(Url);
 if (GetFileExtends(Url).Trim().ToLower() != "jpg")
            if (GetFileExtends(Url).Trim().ToLower() != "jpg")
 newfilename = StringFileName;
                newfilename = StringFileName;
 else
            else
 newfilename = DateRndName(ra) + "Addpic." + GetFileExtends(Url);
                newfilename = DateRndName(ra) + "Addpic." + GetFileExtends(Url);
 string StringFilePath = Path + StringFileName;
            string StringFilePath = Path + StringFileName;
 string newfilepath = Path + newfilename;
            string newfilepath = Path + newfilename;
 string retname = string.Empty;
            string retname = string.Empty;
 try
            try

 
             {
{
 MSXML2.XMLHTTP _xmlhttp = new MSXML2.XMLHTTPClass();
                MSXML2.XMLHTTP _xmlhttp = new MSXML2.XMLHTTPClass();
 _xmlhttp.open("GET", Url, false, null, null);
                _xmlhttp.open("GET", Url, false, null, null);
 _xmlhttp.send("");
                _xmlhttp.send("");
 if (_xmlhttp.readyState == 4)
                if (_xmlhttp.readyState == 4)

 
                 {
{
 if (System.IO.File.Exists(StringFilePath))
                    if (System.IO.File.Exists(StringFilePath))
 System.IO.File.Delete(StringFilePath);
                        System.IO.File.Delete(StringFilePath);
 System.IO.FileStream fs = new System.IO.FileStream(StringFilePath, System.IO.FileMode.CreateNew);
                    System.IO.FileStream fs = new System.IO.FileStream(StringFilePath, System.IO.FileMode.CreateNew);
 System.IO.BinaryWriter w = new System.IO.BinaryWriter(fs);
                    System.IO.BinaryWriter w = new System.IO.BinaryWriter(fs);
 w.Write((byte[])_xmlhttp.responseBody);
                    w.Write((byte[])_xmlhttp.responseBody);
 w.Close();
                    w.Close();
 fs.Close();
                    fs.Close();
 if (GetFileExtends(Url).Trim().ToLower() == "jpg")
                    if (GetFileExtends(Url).Trim().ToLower() == "jpg")

 
                     {
{
 function myfunction = new function();
                        function myfunction = new function();
 //myfunction.AddShuiYinWord(StringFilePath, newfilepath);
                        //myfunction.AddShuiYinWord(StringFilePath, newfilepath);
 service myserver=new service();
                        service myserver=new service();
 myfunction.AddShuiYinPic(StringFilePath, newfilepath, HttpContext.Current.Server.MapPath(myserver.myweblogo));
                        myfunction.AddShuiYinPic(StringFilePath, newfilepath, HttpContext.Current.Server.MapPath(myserver.myweblogo));
 }
                    }

 }
                }
 else
                else
 throw new Exception(_xmlhttp.statusText);
                    throw new Exception(_xmlhttp.statusText);
 }
            }
 catch (Exception ex)
            catch (Exception ex)

 
             {
{

 }
            }
 return newfilename;
            return newfilename;
 }
        }
 #endregion
        #endregion


 替换网页中的换行和引号#region 替换网页中的换行和引号
        替换网页中的换行和引号#region 替换网页中的换行和引号

 /**//**********************************
        /**//**********************************
 * 函数名称:ReplaceEnter
         * 函数名称:ReplaceEnter
 * 功能说明:替换网页中的换行和引号
         * 功能说明:替换网页中的换行和引号
 * 参    数:HtmlCode:html源代码
         * 参    数:HtmlCode:html源代码
 * 调用示例:
         * 调用示例:
 *          GetRemoteObj o = new GetRemoteObj();
         *          GetRemoteObj o = new GetRemoteObj();
 *          string Url = @"http://www.baidu.com";
         *          string Url = @"http://www.baidu.com";
 *          string HtmlCode = o.GetRemoteHtmlCode(Url);
         *          string HtmlCode = o.GetRemoteHtmlCode(Url);
 *          string s = o.ReplaceEnter(HtmlCode);
         *          string s = o.ReplaceEnter(HtmlCode);
 *          Response.Write(s);
         *          Response.Write(s);
 *          o.Dispose();
         *          o.Dispose();
 * ********************************/
         * ********************************/

 /**//// <summary>
        /**//// <summary>
 /// 替换网页中的换行和引号
        /// 替换网页中的换行和引号
 /// </summary>
        /// </summary>
 /// <param name="HtmlCode">HTML源代码</param>
        /// <param name="HtmlCode">HTML源代码</param>
 /// <returns></returns>
        /// <returns></returns>
 public string ReplaceEnter(string HtmlCode)
        public string ReplaceEnter(string HtmlCode)

 
         {
{
 string s = "";
            string s = "";
 if (HtmlCode == null || HtmlCode == "")
            if (HtmlCode == null || HtmlCode == "")
 s = "";
                s = "";
 else
            else
 s = HtmlCode.Replace("\"", "");
                s = HtmlCode.Replace("\"", "");
 s = s.Replace("\r", "");
            s = s.Replace("\r", "");
 s = s.Replace("\n", "");
            s = s.Replace("\n", "");
 return s;
            return s;
 }
        }

 #endregion
        #endregion               


 执行正则提取出值#region 执行正则提取出值
        执行正则提取出值#region 执行正则提取出值

 /**//**********************************
        /**//**********************************
 * 函数名称:GetRegValue
         * 函数名称:GetRegValue
 * 功能说明:执行正则提取出值
         * 功能说明:执行正则提取出值
 * 参    数:HtmlCode:html源代码
         * 参    数:HtmlCode:html源代码
 * 调用示例:
         * 调用示例:
 *          GetRemoteObj o = new GetRemoteObj();
         *          GetRemoteObj o = new GetRemoteObj();
 *          string Url = @"http://www.baidu.com";
         *          string Url = @"http://www.baidu.com";
 *          string HtmlCode = o.GetRemoteHtmlCode(Url);
         *          string HtmlCode = o.GetRemoteHtmlCode(Url);
 *          string s = o.ReplaceEnter(HtmlCode);
         *          string s = o.ReplaceEnter(HtmlCode);
 *          string Reg="<title>.+?</title>";
         *          string Reg="<title>.+?</title>";
 *          string GetValue=o.GetRegValue(Reg,HtmlCode)
         *          string GetValue=o.GetRegValue(Reg,HtmlCode)
 *          Response.Write(GetValue);
         *          Response.Write(GetValue);
 *          o.Dispose();
         *          o.Dispose();
 * ********************************/
         * ********************************/

 /**//// <summary>
        /**//// <summary>
 /// 执行正则提取出值
        /// 执行正则提取出值
 /// </summary>
        /// </summary>
 /// <param name="RegexString">正则表达式</param>
        /// <param name="RegexString">正则表达式</param>
 /// <param name="RemoteStr">HtmlCode源代码</param>
        /// <param name="RemoteStr">HtmlCode源代码</param>
 /// <returns></returns>
        /// <returns></returns>
 public string  GetRegValue(string RegexString, string RemoteStr)
        public string  GetRegValue(string RegexString, string RemoteStr)

 
         {
{
 string MatchVale = "";
            string MatchVale = "";
 Regex r = new Regex(RegexString);
            Regex r = new Regex(RegexString);
 Match m = r.Match(RemoteStr);
            Match m = r.Match(RemoteStr);
 if (m.Success)
            if (m.Success)

 
             {
{
 MatchVale = m.Value;
                MatchVale = m.Value;
 }
            }
 return MatchVale;
            return MatchVale;
 }
        }
 #endregion
        #endregion        


 替换HTML源代码#region 替换HTML源代码
        替换HTML源代码#region 替换HTML源代码

 /**//**********************************
        /**//**********************************
 * 函数名称:RemoveHTML
         * 函数名称:RemoveHTML
 * 功能说明:替换HTML源代码
         * 功能说明:替换HTML源代码
 * 参    数:HtmlCode:html源代码
         * 参    数:HtmlCode:html源代码
 * 调用示例:
         * 调用示例:
 *          GetRemoteObj o = new GetRemoteObj();
         *          GetRemoteObj o = new GetRemoteObj();
 *          string Url = @"http://www.baidu.com";
         *          string Url = @"http://www.baidu.com";
 *          string HtmlCode = o.GetRemoteHtmlCode(Url);
         *          string HtmlCode = o.GetRemoteHtmlCode(Url);
 *          string s = o.ReplaceEnter(HtmlCode);
         *          string s = o.ReplaceEnter(HtmlCode);
 *          string Reg="<title>.+?</title>";
         *          string Reg="<title>.+?</title>";
 *          string GetValue=o.GetRegValue(Reg,HtmlCode)
         *          string GetValue=o.GetRegValue(Reg,HtmlCode)
 *          Response.Write(GetValue);
         *          Response.Write(GetValue);
 *          o.Dispose();
         *          o.Dispose();
 * ********************************/
         * ********************************/

 /**//// <summary>
        /**//// <summary>
 /// 替换HTML源代码
        /// 替换HTML源代码
 /// </summary>
        /// </summary>
 /// <param name="HtmlCode">html源代码</param>
        /// <param name="HtmlCode">html源代码</param>
 /// <returns></returns>
        /// <returns></returns>
 public string RemoveHTML(string HtmlCode)
        public string RemoveHTML(string HtmlCode)

 
         {
{
 string MatchVale = HtmlCode;
            string MatchVale = HtmlCode;          
 foreach (Match s in Regex.Matches(HtmlCode, "<.+?>"))
            foreach (Match s in Regex.Matches(HtmlCode, "<.+?>"))

 
             {
{
 MatchVale = MatchVale.Replace(s.Value, "");
                MatchVale = MatchVale.Replace(s.Value, "");
 }
            }
 return MatchVale;
            return MatchVale;        
 }
        }

 #endregion
        #endregion


 匹配页面的链接#region 匹配页面的链接
        匹配页面的链接#region 匹配页面的链接

 /**//**********************************
        /**//**********************************
 * 函数名称:GetHref
         * 函数名称:GetHref
 * 功能说明:匹配页面的链接
         * 功能说明:匹配页面的链接
 * 参    数:HtmlCode:html源代码
         * 参    数:HtmlCode:html源代码
 * 调用示例:
         * 调用示例:
 *          GetRemoteObj o = new GetRemoteObj();
         *          GetRemoteObj o = new GetRemoteObj();
 *          string Url = @"http://www.baidu.com";
         *          string Url = @"http://www.baidu.com";
 *          string HtmlCode = o.GetRemoteHtmlCode(Url);
         *          string HtmlCode = o.GetRemoteHtmlCode(Url);
 *          string s = o.GetHref(HtmlCode);
         *          string s = o.GetHref(HtmlCode);
 *          Response.Write(s);
         *          Response.Write(s);
 *          o.Dispose();
         *          o.Dispose();
 * ********************************/
         * ********************************/

 /**//// <summary>
        /**//// <summary>
 /// 获取页面的链接正则
        /// 获取页面的链接正则
 /// </summary>
        /// </summary>
 /// <param name="HtmlCode"></param>
        /// <param name="HtmlCode"></param>
 /// <returns></returns>
        /// <returns></returns>
 public string GetHref(string HtmlCode)
        public string GetHref(string HtmlCode)

 
         {
{
 string MatchVale = "";
            string MatchVale = "";
 string Reg = @"(h|H)(r|R)(e|E)(f|F) *= *('|"")?((\w|\\|\/|\.|:|-|_)+)[\S]*";
            string Reg = @"(h|H)(r|R)(e|E)(f|F) *= *('|"")?((\w|\\|\/|\.|:|-|_)+)[\S]*";  
 foreach(Match m in Regex.Matches(HtmlCode,Reg))
            foreach(Match m in Regex.Matches(HtmlCode,Reg))

 
             {
{
 MatchVale += (m.Value).ToLower().Replace("href=", "").Trim() + "|";
                MatchVale += (m.Value).ToLower().Replace("href=", "").Trim() + "|";
 }
            }
 return MatchVale;
            return MatchVale;         
 }
        }
 #endregion
        #endregion


 匹配页面的图片地址#region 匹配页面的图片地址
        匹配页面的图片地址#region 匹配页面的图片地址

 /**//**********************************
        /**//**********************************
 * 函数名称:GetImgSrc
         * 函数名称:GetImgSrc
 * 功能说明:匹配页面的图片地址
         * 功能说明:匹配页面的图片地址
 * 参    数:HtmlCode:html源代码;imgHttp:要补充的http.当比如:<img src="bb/x.gif">则要补充http://www.baidu.com/,当包含http信息时,则可以为空
         * 参    数:HtmlCode:html源代码;imgHttp:要补充的http.当比如:<img src="bb/x.gif">则要补充http://www.baidu.com/,当包含http信息时,则可以为空
 * 调用示例:
         * 调用示例:
 *          GetRemoteObj o = new GetRemoteObj();
         *          GetRemoteObj o = new GetRemoteObj();
 *          string Url = @"http://www.baidu.com";
         *          string Url = @"http://www.baidu.com";
 *          string HtmlCode = o.GetRemoteHtmlCode(Url);
         *          string HtmlCode = o.GetRemoteHtmlCode(Url);
 *          string s = o.GetImgSrc(HtmlCode,"http://www.baidu.com/");
         *          string s = o.GetImgSrc(HtmlCode,"http://www.baidu.com/");
 *          Response.Write(s);
         *          Response.Write(s);
 *          o.Dispose();
         *          o.Dispose();
 * ********************************/
         * ********************************/

 /**//// <summary>
        /**//// <summary>
 /// 匹配页面的图片地址
        /// 匹配页面的图片地址
 /// </summary>
        /// </summary>
 /// <param name="HtmlCode"></param>
        /// <param name="HtmlCode"></param>
 /// <param name="imgHttp">要补充的http://路径信息</param>
        /// <param name="imgHttp">要补充的http://路径信息</param>
 /// <returns></returns>
        /// <returns></returns>
 public string GetImgSrc(string HtmlCode, string imgHttp)
        public string GetImgSrc(string HtmlCode, string imgHttp)

 
         {
{
 string MatchVale = "";
            string MatchVale = "";
 string Reg = @"<img.+?>";
            string Reg = @"<img.+?>";
 foreach (Match m in Regex.Matches(HtmlCode.ToLower(), Reg))
            foreach (Match m in Regex.Matches(HtmlCode.ToLower(), Reg))

 
             {
{
 MatchVale += GetImg((m.Value).ToLower().Trim(), imgHttp) + "|";
                MatchVale += GetImg((m.Value).ToLower().Trim(), imgHttp) + "|";
 }
            }
 
            
 return MatchVale;
            return MatchVale;
 }
        }

 /**//// <summary>
        /**//// <summary>
 /// 匹配<img src="" />中的图片路径实际链接
        /// 匹配<img src="" />中的图片路径实际链接
 /// </summary>
        /// </summary>
 /// <param name="ImgString"><img src="" />字符串</param>
        /// <param name="ImgString"><img src="" />字符串</param>
 /// <returns></returns>
        /// <returns></returns>
 public string GetImg(string ImgString, string imgHttp)
        public string GetImg(string ImgString, string imgHttp)

 
         {
{
 string MatchVale = "";
            string MatchVale = "";
 string Reg = @"src=.+\.(bmp|jpg|gif|png|)";
            string Reg = @"src=.+\.(bmp|jpg|gif|png|)";
 foreach (Match m in Regex.Matches(ImgString.ToLower(), Reg))
            foreach (Match m in Regex.Matches(ImgString.ToLower(), Reg))

 
             {
{
 MatchVale += (m.Value).ToLower().Trim().Replace("src=","");
                MatchVale += (m.Value).ToLower().Trim().Replace("src=","");
 }
            }
 if (MatchVale.IndexOf(".net") != -1 || MatchVale.IndexOf(".com") != -1 || MatchVale.IndexOf(".org") != -1 || MatchVale.IndexOf(".cn") != -1 || MatchVale.IndexOf(".cc") != -1 || MatchVale.IndexOf(".info") != -1 || MatchVale.IndexOf(".biz") != -1 || MatchVale.IndexOf(".tv") != -1)
            if (MatchVale.IndexOf(".net") != -1 || MatchVale.IndexOf(".com") != -1 || MatchVale.IndexOf(".org") != -1 || MatchVale.IndexOf(".cn") != -1 || MatchVale.IndexOf(".cc") != -1 || MatchVale.IndexOf(".info") != -1 || MatchVale.IndexOf(".biz") != -1 || MatchVale.IndexOf(".tv") != -1)
 return (MatchVale);
            return (MatchVale);
 else
            else
 return (imgHttp+MatchVale);
            return (imgHttp+MatchVale);
 }
        }

 #endregion
        #endregion


 替换通过正则获取字符串所带的正则首尾匹配字符串#region 替换通过正则获取字符串所带的正则首尾匹配字符串
        替换通过正则获取字符串所带的正则首尾匹配字符串#region 替换通过正则获取字符串所带的正则首尾匹配字符串

 /**//**********************************
        /**//**********************************
 * 函数名称:GetHref
         * 函数名称:GetHref
 * 功能说明:匹配页面的链接
         * 功能说明:匹配页面的链接
 * 参    数:HtmlCode:html源代码
         * 参    数:HtmlCode:html源代码
 * 调用示例:
         * 调用示例:
 *          GetRemoteObj o = new GetRemoteObj();
         *          GetRemoteObj o = new GetRemoteObj();
 *          string Url = @"http://www.baidu.com";
         *          string Url = @"http://www.baidu.com";
 *          string HtmlCode = o.GetRemoteHtmlCode(Url);
         *          string HtmlCode = o.GetRemoteHtmlCode(Url);
 *          string s = o.RegReplace(HtmlCode,"<title>","</title>");
         *          string s = o.RegReplace(HtmlCode,"<title>","</title>");
 *          Response.Write(s);
         *          Response.Write(s);
 *          o.Dispose();
         *          o.Dispose();
 * ********************************/
         * ********************************/

 /**//// <summary>
        /**//// <summary>
 /// 替换通过正则获取字符串所带的正则首尾匹配字符串
        /// 替换通过正则获取字符串所带的正则首尾匹配字符串
 /// </summary>
        /// </summary>
 /// <param name="RegValue">要替换的值</param>
        /// <param name="RegValue">要替换的值</param>
 /// <param name="regStart">正则匹配的首字符串</param>
        /// <param name="regStart">正则匹配的首字符串</param>
 /// <param name="regEnd">正则匹配的尾字符串</param>
        /// <param name="regEnd">正则匹配的尾字符串</param>
 /// <returns></returns>
        /// <returns></returns>
 public string RegReplace(string RegValue, string regStart,string regEnd)
        public string RegReplace(string RegValue, string regStart,string regEnd)

 
         {
{
 string s = RegValue;
            string s = RegValue;
 if (RegValue != "" && RegValue != null)
            if (RegValue != "" && RegValue != null)

 
             {
{
 if (regStart != "" && regStart != null)
                if (regStart != "" && regStart != null)

 
                 {
{
 s = s.Replace(regStart, "");
                    s = s.Replace(regStart, "");
 }
                }
 if (regEnd != "" && regEnd != null)
                if (regEnd != "" && regEnd != null)

 
                 {
{
 s = s.Replace(regEnd, "");
                    s = s.Replace(regEnd, "");
 }
                }
 }
            }
 return s;
            return s;
 }
        }
 #endregion
        #endregion


 
     


 }
}

 }
} 
 
                    
                     
                    
                 
                    
                 
                
            
         
         浙公网安备 33010602011771号
浙公网安备 33010602011771号