c# 獲取網(wǎng)頁(yè)中指定的字符串信息的實(shí)例代碼
更新時(shí)間:2013年04月28日 14:48:36 作者:
c# 獲取網(wǎng)頁(yè)中指定的字符串信息的實(shí)例代碼,需要的朋友可以參考一下
復(fù)制代碼 代碼如下:
private void button2_Click(object sender, EventArgs e)
{
// Create a request for the URL.
WebRequest request = WebRequest.Create("http://www.baidu.com/");
// If required by the server, set the credentials.
request.Credentials = CredentialCache.DefaultCredentials;
// Get the response.
HttpWebResponse response = (HttpWebResponse)request.GetResponse();
// Display the status.
MessageBox.Show(response.StatusDescription);
Console.WriteLine(response.StatusDescription);
// Get the stream containing content returned by the server.
Stream dataStream = response.GetResponseStream();
// Open the stream using a StreamReader for easy access.
StreamReader reader = new StreamReader(dataStream, Encoding.Default);
// Read the content.
string responseFromServer = reader.ReadToEnd();
//截取數(shù)據(jù)
int i = responseFromServer.IndexOf("京");
string dataBid = responseFromServer.Substring(i, 12);
// Display the content.
MessageBox.Show(dataBid);
Console.WriteLine(responseFromServer);
// Cleanup the streams and the response.
reader.Close();
dataStream.Close();
response.Close();
}
相關(guān)文章
C#實(shí)現(xiàn)Access通用訪問(wèn)類OleDbHelper完整實(shí)例
這篇文章主要介紹了C#實(shí)現(xiàn)Access通用訪問(wèn)類OleDbHelper,結(jié)合完整實(shí)例形式分析了C#針對(duì)access數(shù)據(jù)庫(kù)的連接、查詢、遍歷、分頁(yè)顯示等相關(guān)操作技巧,需要的朋友可以參考下2017-02-02C#實(shí)現(xiàn)簡(jiǎn)單學(xué)生成績(jī)管理系統(tǒng)
這篇文章主要為大家詳細(xì)介紹了C#實(shí)現(xiàn)簡(jiǎn)單學(xué)生成績(jī)管理系統(tǒng),文中示例代碼介紹的非常詳細(xì),具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下2022-08-08用.NET創(chuàng)建Windows服務(wù)的方法
用.NET創(chuàng)建Windows服務(wù)的方法...2007-03-03淺析C#中的Main(String[] args)參數(shù)輸入問(wèn)題
本篇文章主要是對(duì)C#中的Main(String[] args)參數(shù)輸入問(wèn)題進(jìn)行了詳細(xì)的介紹,需要的朋友可以過(guò)來(lái)參考下,希望對(duì)大家有所幫助2014-01-01c#基于NVelocity實(shí)現(xiàn)代碼生成
這篇文章主要介紹了c#基于NVelocity實(shí)現(xiàn)代碼生成的方法,幫助大家更好的理解和使用c#,感興趣的朋友可以了解下2021-01-01