從Internet上抓取指定URL的源碼的方案(C#)(3)_.Net教程
推薦:ASP.NET對IIS中的虛擬目錄進(jìn)行操作//假如虛擬目錄名為"Webtest",先在項目中引用 //System.DirectoryServices.dll,再 using System.DirectoryServices; protected System.DirectoryServices.DirectoryEntry di
/// <summary>
/// 輸出文件路徑
/// </summary>
public string OutFilePath
{
get{return outFilePath;}
set{outFilePath=value;}
}
/// <summary>
/// 返回的字符串
/// </summary>
public string OutString
{
get{return outString;}
}
/// <summary>
/// 返回提示信息
/// </summary>
public string NoteMessage
{
get{return noteMessage;}
}
#endregion
#region 構(gòu)造函數(shù)
public GetPageCode()
{
}
#endregion
#region 公共方法
/// <summary>
/// 讀取指定URL地址,存到指定文件中
/// </summary>
public void GetSource()
{
WebRequest request = WebRequest.Create(this.url);
//使用代理服務(wù)器的處理
if(this.proxyState==1)
{
//默認(rèn)讀取80端口的數(shù)據(jù)
if(this.proxyPort==null)
this.ProxyPort="80";
WebProxy myProxy=new WebProxy();
myProxy = (WebProxy)request.Proxy;
myProxy.Address = new Uri(this.ProxyAddress ":" this.ProxyPort);
myProxy.Credentials = new NetworkCredential(this.proxyAccount, this.proxyPassword, this.ProxyDomain);
request.Proxy = myProxy;
}
try
{
//請求服務(wù)
WebResponse response = request.GetResponse();
//返回信息
Stream resStream = response.GetResponseStream();
StreamReader sr = new StreamReader(resStream, System.Text.Encoding.Default);
string tempCode= sr.ReadToEnd();
resStream.Close();
sr.Close();
//如果輸出文件路徑為空,便將得到的內(nèi)容賦給OutString屬性
if(this.outFilePath==null)
{
this.outString=tempCode;
}
else
{
FileInfo fi = new FileInfo(this.outFilePath);
//如果存在文件則先干掉
if(fi.Exists)
fi.Delete();
StreamWriter sw = new StreamWriter(this.outFilePath,true,Encoding.Default);
sw.Write(tempCode);
sw.Flush();
sw.Close();
}
}
catch
{
this.noteMessage="出錯了,請檢查網(wǎng)絡(luò)是否連通;";
}
}
#endregion
}
}
分享:ASP.NET中數(shù)據(jù)庫的操作初步----增加、刪除、修改注意:本文暫時不講解數(shù)據(jù)庫的數(shù)據(jù)調(diào)出和顯示,因為他涉及的東西比較多,所以我們將另外詳細(xì)講解。本文主要要講的是數(shù)據(jù)庫的增加、刪除、修改。 一、定義OleDbCommand類型變量:MyCommand
- asp.net如何得到GRIDVIEW中某行某列值的方法
- .net SMTP發(fā)送Email實例(可帶附件)
- js實現(xiàn)廣告漂浮效果的小例子
- asp.net Repeater 數(shù)據(jù)綁定的具體實現(xiàn)
- Asp.Net 無刷新文件上傳并顯示進(jìn)度條的實現(xiàn)方法及思路
- Asp.net獲取客戶端IP常見代碼存在的偽造IP問題探討
- VS2010 水晶報表的使用方法
- ASP.NET中操作SQL數(shù)據(jù)庫(連接字符串的配置及獲取)
- asp.net頁面?zhèn)髦禍y試實例代碼
- DataGridView - DataGridViewCheckBoxCell的使用介紹
- asp.net中javascript的引用(直接引入和間接引入)
- 三層+存儲過程實現(xiàn)分頁示例代碼
- 相關(guān)鏈接:
- 教程說明:
.Net教程-從Internet上抓取指定URL的源碼的方案(C#)(3)
。