c# 獲取網(wǎng)頁中指定的字符串信息的實(shí)例代碼
更新時(shí)間:2013年04月28日 14:48:36 作者:
c# 獲取網(wǎng)頁中指定的字符串信息的實(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)DataTable數(shù)據(jù)行列轉(zhuǎn)換
這篇文章介紹了C#實(shí)現(xiàn)DataTable數(shù)據(jù)行列轉(zhuǎn)換的方法,文中通過示例代碼介紹的非常詳細(xì)。對(duì)大家的學(xué)習(xí)或工作具有一定的參考借鑒價(jià)值,需要的朋友可以參考下2022-04-04
深入C#中使用SqlDbType.Xml類型參數(shù)的使用詳解
本篇文章是對(duì)在C#中使用SqlDbType.Xml類型參數(shù)的使用進(jìn)行了詳細(xì)的分析介紹,需要的朋友參考下2013-05-05
C#Process的OutputDataReceived事件不觸發(fā)問題及解決
這篇文章主要介紹了C#Process的OutputDataReceived事件不觸發(fā)問題及解決方案,具有很好的參考價(jià)值,希望對(duì)大家有所幫助。如有錯(cuò)誤或未考慮完全的地方,望不吝賜教2023-02-02

