All articles| All Pictures| All Softwares| All Video| Go home page| Write articles| Upload pictures

Reading number is top 10 articles
漫谈Visual,C#的组件设计方法_[Asp.Net教程]
中英文对照学习认识一下XML语言_[XML教程]
SQL Server2000安全管理机制详解_[SQL Server教程]
如何使用SQL Server数据库嵌套子查询_[SQL Server教程]
PHP分页实例:用PHP实现网页开发中的翻页跳转_[PHP教程]
《Effective,C#》-使用成员初始化语句_[Asp.Net教程]
asp.net从数据库导出数据到word、excel、txt文本文件_[Asp.Net教程]
ASP.NET中的doPostBack脚本函数实例_.net资料_编程技术
adapter和facade模式在Ajax中的应用_[AJAX教程]
Ajax 及其入门基础(2)_[AJAX教程]
Reading number is top 10 pictures
为什么别人说你是疯子
真正的国产-非模拍 贵在是真实2
青春清纯美女大集合1
Absolutely shocked. National geographic 50 animal photographys2
刘亦菲写真集1
Black and white also sexy--YanLiu1
BingBingFan apple dew point photo gallery5
Summer is most suitable for young people to travel in China2
The terra-cotta warriors3
Seductive beauty of crime2
Download software ranking
Eclipse-CALMSANNY (second edition)
Eclipse 4.2.1 For Win32
Unix video tutorial15
Proficient in JavaScript
传奇私服架设教程-chm
美女游泳记
C#编程思想
Boxer's Top ten classic battle1
WebService在.NET中的实战应用教学视频 → 第3集
jdk1.5
归海一刀 published in(发表于) 2014/1/30 0:58:13 Edit(编辑)
ASP.NET(C#)经典采集代码_[Asp.Net教程]

ASP.NET(C#)经典采集代码_[Asp.Net教程]

ASP.NET(C#)经典采集代码_[Asp.Net教程]

using System;
using System.Data;
using System.Configuration;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using System.Drawing;
using MSXML2;
using System.Text.RegularExpressions;
namespace wenweifeng
{
/**////


/// CaiJi 的摘要说明
///

public class CaiJi
{
public CaiJi()
{
//
// TOD 在此处添加构造函数逻辑
//
}
~CaiJi()
{
Dispose();
}
public void Dispose()
{
GC.SuppressFinalize(this);
}

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

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


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


/// 取得文件后缀
///

/// 文件名称
///
public string GetFileExtends(string filename)
{
string ext = null;
if (filename.IndexOf('.') > 0)
{
string[] fs = filename.Split('.');
ext = fs[fs.Length - 1];
}
return ext;
}
#endregion


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


/// 获取远程文件源代码
///

/// 远程url
///
public string GetRemoteHtmlCode(string Url)
{
string s = "";
MSXML2.XMLHTTP _xmlhttp = new MSXML2.XMLHTTPClass();
_xmlhttp.open("GET", Url, false, null, null);
_xmlhttp.send("");
if (_xmlhttp.readyState == 4)
{
s = System.Text.Encoding.Default.GetString((byte[])_xmlhttp.responseBody);
}
return s;
}


#endregion


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


/// 保存远程文件
///

/// 远程url
/// 保存到的路径
///
public string RemoteSave(string Url, string Path)
{

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


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


}
return newfilename;
}
#endregion


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


/// 替换网页中的换行和引号
///

/// HTML源代码
///
public string ReplaceEnter(string HtmlCode)
{
string s = "";
if (HtmlCode == null || HtmlCode == "")
s = "";
else
s = HtmlCode.Replace("\"", "");
s = s.Replace("\r", "");
s = s.Replace("\n", "");
return s;
}


#endregion


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


/// 执行正则提取出值
///

/// 正则表达式
/// HtmlCode源代码
///
public string GetRegValue(string RegexString, string RemoteStr)
{
string MatchVale = "";
Regex r = new Regex(RegexString);
Match m = r.Match(RemoteStr);
if (m.Success)
{
MatchVale = m.Value;
}
return MatchVale;
}
#endregion


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


/// 替换HTML源代码
///

/// html源代码
///
public string RemoveHTML(string HtmlCode)
{
string MatchVale = HtmlCode;
foreach (Match s in Regex.Matches(HtmlCode, "<.+?>"))
{
MatchVale = MatchVale.Replace(s.Value, "");
}
return MatchVale;
}


#endregion


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


/// 获取页面的链接正则
///

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


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


/// 匹配页面的图片地址
///

///
/// 要补充的http://路径信息
///
public string GetImgSrc(string HtmlCode, string imgHttp)
{
string MatchVale = "";
string Reg = @"";
foreach (Match m in Regex.Matches(HtmlCode.ToLower(), Reg))
{
MatchVale += GetImg((m.Value).ToLower().Trim(), imgHttp) + "|";
}

return MatchVale;
}
/**////
/// 匹配中的图片路径实际链接
///

/// 字符串
///
public string GetImg(string ImgString, string imgHttp)
{
string MatchVale = "";
string Reg = @"src=.+\.(bmp|jpg|gif|png|)";
foreach (Match m in Regex.Matches(ImgString.ToLower(), Reg))
{
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)
return (MatchVale);
else
return (imgHttp+MatchVale);
}


#endregion


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


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

/// 要替换的值
/// 正则匹配的首字符串
/// 正则匹配的尾字符串
///
public string RegReplace(string RegValue, string regStart,string regEnd)
{
string s = RegValue;
if (RegValue != "" && RegValue != null)
{
if (regStart != "" && regStart != null)
{
s = s.Replace(regStart, "");
}
if (regEnd != "" && regEnd != null)
{
s = s.Replace(regEnd, "");
}
}
return s;
}
#endregion

}


}







添加到del.icio.us 添加到新浪ViVi 添加到百度搜藏 添加到POCO网摘 添加到天天网摘365Key 添加到和讯网摘 添加到天极网摘 添加到黑米书签 添加到QQ书签 添加到雅虎收藏 添加到奇客发现 diigo it 添加到饭否 添加到飞豆订阅 添加到抓虾收藏 添加到鲜果订阅 digg it 貼到funP 添加到有道阅读 Live Favorites 添加到Newsvine 打印本页 用Email发送本页 在Facebook上分享


Disclaimer Privacy Policy About us Site Map

If you have any requirements, please contact webmaster。(如果有什么要求,请联系站长)
Copyright ©2011-
uuhomepage.com, Inc. All rights reserved.