Skip Navigation Links
技术文档
·网站建设
·软件使用
·图形设计
·程序开发
·网络应用
·电脑技巧
 
公司介绍
·公司简介
·索仕SRCOS网络应用平台
·索仕网站管理系统
·影视广告制作
·联系我们
 
 

ASP.NET(C#)经典采集代码

12/3/2009 9:34:30 AM
ASP.NET(C#)经典采集代码using System;
ASP.NET(C#)经典采集代码
using System.Data;
ASP.NET(C#)经典采集代码
using System.Configuration;
ASP.NET(C#)经典采集代码
using System.Web;
ASP.NET(C#)经典采集代码
using System.Web.Security;
ASP.NET(C#)经典采集代码
using System.Web.UI;
ASP.NET(C#)经典采集代码
using System.Web.UI.WebControls;
ASP.NET(C#)经典采集代码
using System.Web.UI.WebControls.WebParts;
ASP.NET(C#)经典采集代码
using System.Web.UI.HtmlControls;
ASP.NET(C#)经典采集代码
using System.Drawing;
ASP.NET(C#)经典采集代码
using MSXML2;
ASP.NET(C#)经典采集代码
using System.Text.RegularExpressions;
ASP.NET(C#)经典采集代码
namespace wenweifeng
ASP.NET(C#)经典采集代码
{
ASP.NET(C#)经典采集代码    
/// <summary>
ASP.NET(C#)经典采集代码    
/// CaiJi 的摘要说明
ASP.NET(C#)经典采集代码    
/// </summary>

ASP.NET(C#)经典采集代码    public class CaiJi
ASP.NET(C#)经典采集代码    
{
ASP.NET(C#)经典采集代码        
public CaiJi()
ASP.NET(C#)经典采集代码        
{
ASP.NET(C#)经典采集代码            
//
ASP.NET(C#)经典采集代码            
// TODO: 在此处添加构造函数逻辑
ASP.NET(C#)经典采集代码            
//
ASP.NET(C#)经典采集代码
        }

ASP.NET(C#)经典采集代码        
~CaiJi()
ASP.NET(C#)经典采集代码        
{
ASP.NET(C#)经典采集代码            Dispose();
ASP.NET(C#)经典采集代码        }

ASP.NET(C#)经典采集代码        
public void Dispose()
ASP.NET(C#)经典采集代码        
{
ASP.NET(C#)经典采集代码         GC.SuppressFinalize(
this);
ASP.NET(C#)经典采集代码        }

ASP.NET(C#)经典采集代码  
ASP.NET(C#)经典采集代码     
#region 日期随机函数
ASP.NET(C#)经典采集代码        
/**********************************
ASP.NET(C#)经典采集代码         * 函数名称:DateRndName
ASP.NET(C#)经典采集代码         * 功能说明:日期随机函数
ASP.NET(C#)经典采集代码         * 参    数:ra:随机数
ASP.NET(C#)经典采集代码         * 调用示例:
ASP.NET(C#)经典采集代码         *          GetRemoteObj o = new GetRemoteObj();
ASP.NET(C#)经典采集代码         *          Random ra = new Random();
ASP.NET(C#)经典采集代码         *          string s = o.DateRndName(ra);
ASP.NET(C#)经典采集代码         *          Response.Write(s);
ASP.NET(C#)经典采集代码         *          o.Dispose();
ASP.NET(C#)经典采集代码         * *******************************
*/

ASP.NET(C#)经典采集代码        
/// <summary>
ASP.NET(C#)经典采集代码        
/// 日期随机函数
ASP.NET(C#)经典采集代码        
/// </summary>
ASP.NET(C#)经典采集代码        
/// <param name="ra">随机数</param>
ASP.NET(C#)经典采集代码        
/// <returns></returns>

ASP.NET(C#)经典采集代码        public  string DateRndName(Random ra)
ASP.NET(C#)经典采集代码        
{
ASP.NET(C#)经典采集代码            DateTime d 
= DateTime.Now;
ASP.NET(C#)经典采集代码            
string s = null, y, m, dd, h, mm, ss;
ASP.NET(C#)经典采集代码            y 
= d.Year.ToString();
ASP.NET(C#)经典采集代码            m 
= d.Month.ToString();
ASP.NET(C#)经典采集代码            
if (m.Length < 2) m = "0" + m;
ASP.NET(C#)经典采集代码            dd 
= d.Day.ToString();
ASP.NET(C#)经典采集代码            
if (dd.Length < 2) dd = "0" + dd;
ASP.NET(C#)经典采集代码            h 
= d.Hour.ToString();
ASP.NET(C#)经典采集代码            
if (h.Length < 2) h = "0" + h;
ASP.NET(C#)经典采集代码            mm 
= d.Minute.ToString();
ASP.NET(C#)经典采集代码            
if (mm.Length < 2) mm = "0" + mm;
ASP.NET(C#)经典采集代码            ss 
= d.Second.ToString();
ASP.NET(C#)经典采集代码            
if (ss.Length < 2) ss = "0" + ss;
ASP.NET(C#)经典采集代码            s 
+= y + ',' + m + ',' + dd + ',' + h + "-" + mm + "-" + ss;
ASP.NET(C#)经典采集代码            s 
+= ra.Next(10000009999999).ToString();
ASP.NET(C#)经典采集代码            
return s;
ASP.NET(C#)经典采集代码        }

ASP.NET(C#)经典采集代码        
#endregion

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

ASP.NET(C#)经典采集代码        
/// <summary>
ASP.NET(C#)经典采集代码        
/// 取得文件后缀
ASP.NET(C#)经典采集代码        
/// </summary>
ASP.NET(C#)经典采集代码        
/// <param name="filename">文件名称</param>
ASP.NET(C#)经典采集代码        
/// <returns></returns>

ASP.NET(C#)经典采集代码        public string GetFileExtends(string filename)
ASP.NET(C#)经典采集代码        
{
ASP.NET(C#)经典采集代码            
string ext = null;
ASP.NET(C#)经典采集代码            
if (filename.IndexOf('.'> 0)
ASP.NET(C#)经典采集代码            
{
ASP.NET(C#)经典采集代码                
string[] fs = filename.Split('.');
ASP.NET(C#)经典采集代码                ext 
= fs[fs.Length - 1];
ASP.NET(C#)经典采集代码            }

ASP.NET(C#)经典采集代码            
return ext;
ASP.NET(C#)经典采集代码        }

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

ASP.NET(C#)经典采集代码        
/// <summary>
ASP.NET(C#)经典采集代码        
/// 获取远程文件源代码
ASP.NET(C#)经典采集代码        
/// </summary>
ASP.NET(C#)经典采集代码        
/// <param name="url">远程url</param>
ASP.NET(C#)经典采集代码        
/// <returns></returns>

ASP.NET(C#)经典采集代码        public string GetRemoteHtmlCode(string Url)
ASP.NET(C#)经典采集代码        
{
ASP.NET(C#)经典采集代码            
string s = "";
ASP.NET(C#)经典采集代码            MSXML2.XMLHTTP _xmlhttp 
= new MSXML2.XMLHTTPClass();
ASP.NET(C#)经典采集代码            _xmlhttp.open(
"GET", Url, falsenullnull);
ASP.NET(C#)经典采集代码            _xmlhttp.send(
"");
ASP.NET(C#)经典采集代码            
if (_xmlhttp.readyState == 4)
ASP.NET(C#)经典采集代码            
{
ASP.NET(C#)经典采集代码                s 
= System.Text.Encoding.Default.GetString((byte[])_xmlhttp.responseBody);
ASP.NET(C#)经典采集代码            }

ASP.NET(C#)经典采集代码            
return s;
ASP.NET(C#)经典采集代码        }

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

ASP.NET(C#)经典采集代码        
/// <summary>
ASP.NET(C#)经典采集代码        
/// 保存远程文件
ASP.NET(C#)经典采集代码        
/// </summary>
ASP.NET(C#)经典采集代码        
/// <param name="Url">远程url</param>
ASP.NET(C#)经典采集代码        
/// <param name="Path">保存到的路径</param>
ASP.NET(C#)经典采集代码        
/// <returns></returns>

ASP.NET(C#)经典采集代码        public string RemoteSave(string Url, string Path)
ASP.NET(C#)经典采集代码        
{
ASP.NET(C#)经典采集代码         
ASP.NET(C#)经典采集代码            Random ra 
= new Random();
ASP.NET(C#)经典采集代码            
string newfilename = string.Empty;
ASP.NET(C#)经典采集代码            
string StringFileName = DateRndName(ra) + "." + GetFileExtends(Url);
ASP.NET(C#)经典采集代码            
if (GetFileExtends(Url).Trim().ToLower() != "jpg")
ASP.NET(C#)经典采集代码                newfilename 
= StringFileName;
ASP.NET(C#)经典采集代码            
else
ASP.NET(C#)经典采集代码                newfilename 
= DateRndName(ra) + "Addpic." + GetFileExtends(Url);
ASP.NET(C#)经典采集代码            
string StringFilePath = Path + StringFileName;
ASP.NET(C#)经典采集代码            
string newfilepath = Path + newfilename;
ASP.NET(C#)经典采集代码            
string retname = string.Empty;
ASP.NET(C#)经典采集代码            
try
ASP.NET(C#)经典采集代码            
{
ASP.NET(C#)经典采集代码                MSXML2.XMLHTTP _xmlhttp 
= new MSXML2.XMLHTTPClass();
ASP.NET(C#)经典采集代码                _xmlhttp.open(
"GET", Url, falsenullnull);
ASP.NET(C#)经典采集代码                _xmlhttp.send(
"");
ASP.NET(C#)经典采集代码                
if (_xmlhttp.readyState == 4)
ASP.NET(C#)经典采集代码                
{
ASP.NET(C#)经典采集代码                    
if (System.IO.File.Exists(StringFilePath))
ASP.NET(C#)经典采集代码                        System.IO.File.Delete(StringFilePath);
ASP.NET(C#)经典采集代码                    System.IO.FileStream fs 
= new System.IO.FileStream(StringFilePath, System.IO.FileMode.CreateNew);
ASP.NET(C#)经典采集代码                    System.IO.BinaryWriter w 
= new System.IO.BinaryWriter(fs);
ASP.NET(C#)经典采集代码                    w.Write((
byte[])_xmlhttp.responseBody);
ASP.NET(C#)经典采集代码                    w.Close();
ASP.NET(C#)经典采集代码                    fs.Close();
ASP.NET(C#)经典采集代码                    
if (GetFileExtends(Url).Trim().ToLower() == "jpg")
ASP.NET(C#)经典采集代码                    
{
ASP.NET(C#)经典采集代码                        function myfunction 
= new function();
ASP.NET(C#)经典采集代码                        
//myfunction.AddShuiYinWord(StringFilePath, newfilepath);
ASP.NET(C#)经典采集代码
                        service myserver=new service();
ASP.NET(C#)经典采集代码                        myfunction.AddShuiYinPic(StringFilePath, newfilepath, HttpContext.Current.Server.MapPath(myserver.myweblogo));
ASP.NET(C#)经典采集代码                    }

ASP.NET(C#)经典采集代码
ASP.NET(C#)经典采集代码                }

ASP.NET(C#)经典采集代码                
else
ASP.NET(C#)经典采集代码                    
throw new Exception(_xmlhttp.statusText);
ASP.NET(C#)经典采集代码            }

ASP.NET(C#)经典采集代码            
catch (Exception ex)
ASP.NET(C#)经典采集代码            
{
ASP.NET(C#)经典采集代码
ASP.NET(C#)经典采集代码            }

ASP.NET(C#)经典采集代码            
return newfilename;
ASP.NET(C#)经典采集代码        }

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

ASP.NET(C#)经典采集代码        
/// <summary>
ASP.NET(C#)经典采集代码        
/// 替换网页中的换行和引号
ASP.NET(C#)经典采集代码        
/// </summary>
ASP.NET(C#)经典采集代码        
/// <param name="HtmlCode">HTML源代码</param>
ASP.NET(C#)经典采集代码        
/// <returns></returns>

ASP.NET(C#)经典采集代码        public string ReplaceEnter(string HtmlCode)
ASP.NET(C#)经典采集代码        
{
ASP.NET(C#)经典采集代码            
string s = "";
ASP.NET(C#)经典采集代码            
if (HtmlCode == null || HtmlCode == "")
ASP.NET(C#)经典采集代码                s 
= "";
ASP.NET(C#)经典采集代码            
else
ASP.NET(C#)经典采集代码                s 
= HtmlCode.Replace("\"""");
ASP.NET(C#)经典采集代码
            s = s.Replace("\r""");
ASP.NET(C#)经典采集代码            s 
= s.Replace("\n""");
ASP.NET(C#)经典采集代码            
return s;
ASP.NET(C#)经典采集代码        }

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

ASP.NET(C#)经典采集代码        
/// <summary>
ASP.NET(C#)经典采集代码        
/// 执行正则提取出值
ASP.NET(C#)经典采集代码        
/// </summary>
ASP.NET(C#)经典采集代码        
/// <param name="RegexString">正则表达式</param>
ASP.NET(C#)经典采集代码        
/// <param name="RemoteStr">HtmlCode源代码</param>
ASP.NET(C#)经典采集代码        
/// <returns></returns>

ASP.NET(C#)经典采集代码        public string  GetRegValue(string RegexString, string RemoteStr)
ASP.NET(C#)经典采集代码        
{
ASP.NET(C#)经典采集代码            
string MatchVale = "";
ASP.NET(C#)经典采集代码            Regex r 
= new Regex(RegexString);
ASP.NET(C#)经典采集代码            Match m 
= r.Match(RemoteStr);
ASP.NET(C#)经典采集代码            
if (m.Success)
ASP.NET(C#)经典采集代码            
{
ASP.NET(C#)经典采集代码                MatchVale 
= m.Value;
ASP.NET(C#)经典采集代码            }

ASP.NET(C#)经典采集代码            
return MatchVale;
ASP.NET(C#)经典采集代码        }

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

ASP.NET(C#)经典采集代码        
/// <summary>
ASP.NET(C#)经典采集代码        
/// 替换HTML源代码
ASP.NET(C#)经典采集代码        
/// </summary>
ASP.NET(C#)经典采集代码        
/// <param name="HtmlCode">html源代码</param>
ASP.NET(C#)经典采集代码        
/// <returns></returns>

ASP.NET(C#)经典采集代码        public string RemoveHTML(string HtmlCode)
ASP.NET(C#)经典采集代码        
{
ASP.NET(C#)经典采集代码            
string MatchVale = HtmlCode;          
ASP.NET(C#)经典采集代码            
foreach (Match s in Regex.Matches(HtmlCode, "<.+?>"))
ASP.NET(C#)经典采集代码            
{
ASP.NET(C#)经典采集代码                MatchVale 
= MatchVale.Replace(s.Value, "");
ASP.NET(C#)经典采集代码            }

ASP.NET(C#)经典采集代码            
return MatchVale;        
ASP.NET(C#)经典采集代码        }

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

ASP.NET(C#)经典采集代码        
/// <summary>
ASP.NET(C#)经典采集代码        
/// 获取页面的链接正则
ASP.NET(C#)经典采集代码        
/// </summary>
ASP.NET(C#)经典采集代码        
/// <param name="HtmlCode"></param>
ASP.NET(C#)经典采集代码        
/// <returns></returns>

ASP.NET(C#)经典采集代码        public string GetHref(string HtmlCode)
ASP.NET(C#)经典采集代码        
{
ASP.NET(C#)经典采集代码            
string MatchVale = "";
ASP.NET(C#)经典采集代码            
string Reg = @"(h|H)(r|R)(e|E)(f|F) *= *('|"")?((\w|\\|\/|\.|:|-|_)+)[\S]*";  
ASP.NET(C#)经典采集代码            
foreach(Match m in Regex.Matches(HtmlCode,Reg))
ASP.NET(C#)经典采集代码            
{
ASP.NET(C#)经典采集代码                MatchVale 
+= (m.Value).ToLower().Replace("href=""").Trim() + "|";
ASP.NET(C#)经典采集代码            }

ASP.NET(C#)经典采集代码            
return MatchVale;         
ASP.NET(C#)经典采集代码        }

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

ASP.NET(C#)经典采集代码        
/// <summary>
ASP.NET(C#)经典采集代码        
/// 匹配页面的图片地址
ASP.NET(C#)经典采集代码        
/// </summary>
ASP.NET(C#)经典采集代码        
/// <param name="HtmlCode"></param>
ASP.NET(C#)经典采集代码        
/// <param name="imgHttp">要补充的http://路径信息</param>
ASP.NET(C#)经典采集代码        
/// <returns></returns>

ASP.NET(C#)经典采集代码        public string GetImgSrc(string HtmlCode, string imgHttp)
ASP.NET(C#)经典采集代码        
{
ASP.NET(C#)经典采集代码            
string MatchVale = "";
ASP.NET(C#)经典采集代码            
string Reg = @"<img.+?>";
ASP.NET(C#)经典采集代码            
foreach (Match m in Regex.Matches(HtmlCode.ToLower(), Reg))
ASP.NET(C#)经典采集代码            
{
ASP.NET(C#)经典采集代码                MatchVale 
+= GetImg((m.Value).ToLower().Trim(), imgHttp) + "|";
ASP.NET(C#)经典采集代码            }

ASP.NET(C#)经典采集代码            
ASP.NET(C#)经典采集代码            
return MatchVale;
ASP.NET(C#)经典采集代码        }

ASP.NET(C#)经典采集代码        
/// <summary>
ASP.NET(C#)经典采集代码        
/// 匹配<img src="" />中的图片路径实际链接
ASP.NET(C#)经典采集代码        
/// </summary>
ASP.NET(C#)经典采集代码        
/// <param name="ImgString"><img src="" />字符串</param>
ASP.NET(C#)经典采集代码        
/// <returns></returns>

ASP.NET(C#)经典采集代码        public string GetImg(string ImgString, string imgHttp)
ASP.NET(C#)经典采集代码        
{
ASP.NET(C#)经典采集代码            
string MatchVale = "";
ASP.NET(C#)经典采集代码            
string Reg = @"src=.+\.(bmp|jpg|gif|png|)";
ASP.NET(C#)经典采集代码            
foreach (Match m in Regex.Matches(ImgString.ToLower(), Reg))
ASP.NET(C#)经典采集代码            
{
ASP.NET(C#)经典采集代码                MatchVale 
+= (m.Value).ToLower().Trim().Replace("src=","");
ASP.NET(C#)经典采集代码            }

ASP.NET(C#)经典采集代码            
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)
ASP.NET(C#)经典采集代码            
return (MatchVale);
ASP.NET(C#)经典采集代码            
else
ASP.NET(C#)经典采集代码            
return (imgHttp+MatchVale);
ASP.NET(C#)经典采集代码        }

ASP.NET(C#)经典采集代码
ASP.NET(C#)经典采集代码        
#endregion
ASP.NET(C#)经典采集代码
ASP.NET(C#)经典采集代码        
#region 替换通过正则获取字符串所带的正则首尾匹配字符串
ASP.NET(C#)经典采集代码        
/**********************************
ASP.NET(C#)经典采集代码         * 函数名称:GetHref
ASP.NET(C#)经典采集代码         * 功能说明:匹配页面的链接
ASP.NET(C#)经典采集代码         * 参    数:HtmlCode:html源代码
ASP.NET(C#)经典采集代码         * 调用示例:
ASP.NET(C#)经典采集代码         *          GetRemoteObj o = new GetRemoteObj();
ASP.NET(C#)经典采集代码         *          string Url = @"
http://www.baidu.com";
ASP.NET(C#)经典采集代码         *          string HtmlCode = o.GetRemoteHtmlCode(Url);
ASP.NET(C#)经典采集代码         *          string s = o.RegReplace(HtmlCode,"<title>","</title>");
ASP.NET(C#)经典采集代码         *          Response.Write(s);
ASP.NET(C#)经典采集代码         *          o.Dispose();
ASP.NET(C#)经典采集代码         * *******************************
*/

ASP.NET(C#)经典采集代码        
/// <summary>
ASP.NET(C#)经典采集代码        
/// 替换通过正则获取字符串所带的正则首尾匹配字符串
ASP.NET(C#)经典采集代码        
/// </summary>
ASP.NET(C#)经典采集代码        
/// <param name="RegValue">要替换的值</param>
ASP.NET(C#)经典采集代码        
/// <param name="regStart">正则匹配的首字符串</param>
ASP.NET(C#)经典采集代码        
/// <param name="regEnd">正则匹配的尾字符串</param>
ASP.NET(C#)经典采集代码        
/// <returns></returns>

ASP.NET(C#)经典采集代码        public string RegReplace(string RegValue, string regStart,string regEnd)
ASP.NET(C#)经典采集代码        
{
ASP.NET(C#)经典采集代码            
string s = RegValue;
ASP.NET(C#)经典采集代码            
if (RegValue != "" && RegValue != null)
ASP.NET(C#)经典采集代码            
{
ASP.NET(C#)经典采集代码                
if (regStart != "" && regStart != null)
ASP.NET(C#)经典采集代码                
{
ASP.NET(C#)经典采集代码                    s 
= s.Replace(regStart, "");
ASP.NET(C#)经典采集代码                }

ASP.NET(C#)经典采集代码                
if (regEnd != "" && regEnd != null)
ASP.NET(C#)经典采集代码                
{
ASP.NET(C#)经典采集代码                    s 
= s.Replace(regEnd, "");
ASP.NET(C#)经典采集代码                }

ASP.NET(C#)经典采集代码            }

ASP.NET(C#)经典采集代码            
return s;
ASP.NET(C#)经典采集代码        }

ASP.NET(C#)经典采集代码        
#endregion
ASP.NET(C#)经典采集代码
ASP.NET(C#)经典采集代码
ASP.NET(C#)经典采集代码     
ASP.NET(C#)经典采集代码
ASP.NET(C#)经典采集代码
ASP.NET(C#)经典采集代码}

ASP.NET(C#)经典采集代码
ASP.NET(C#)经典采集代码}

 

作者:clefoo 来源:博客园
 
 
 
昆明索仕科技开发有限公司 版权所有 Copyright© 2002-2010 Kunming Source Technology Exploitive Co.,LTD. All Rights Reserved.
电话:0871-5627877 业务QQ:163871 联系我们
本站基于:索仕网站信息管理系统建设 版本 2.0.4325