手机
当前位置:查字典教程网 >编程开发 >C#教程 >c# 获取网页中指定的字符串信息的实例代码
c# 获取网页中指定的字符串信息的实例代码
摘要:复制代码代码如下:privatevoidbutton2_Click(objectsender,EventArgse){//Createare...

复制代码 代码如下:

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();

//截取数据

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();

}

【c# 获取网页中指定的字符串信息的实例代码】相关文章:

C#实现通过程序自动抓取远程Web网页信息的代码

C#生成随机字符串的实例

获取字符串中的汉字拼音首字母

C# 中文简体转繁体实现代码

gridview 显示图片的实例代码

C# 实现简单打印的实例代码

c#中分割字符串的几种方法

c#文件的复制,移动,创建(实例代码)

C# zxing二维码写入的实例代码

C#控制台输出进度和百分比的实例代码

精品推荐
分类导航