c# 获取网页中指定的字符串信息的实例代码
更新时间:2013年04月28日 14:48:36 作者:
c# 获取网页中指定的字符串信息的实例代码,需要的朋友可以参考一下
复制代码 代码如下:
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#实现Access通用访问类OleDbHelper完整实例
这篇文章主要介绍了C#实现Access通用访问类OleDbHelper,结合完整实例形式分析了C#针对access数据库的连接、查询、遍历、分页显示等相关操作技巧,需要的朋友可以参考下2017-02-02浅析C#中的Main(String[] args)参数输入问题
本篇文章主要是对C#中的Main(String[] args)参数输入问题进行了详细的介绍,需要的朋友可以过来参考下,希望对大家有所帮助2014-01-01
最新评论