源码网商城,靠谱的源码在线交易网站 我的订单 购物车 帮助

源码网商城

c# 获取网页中指定的字符串信息的实例代码

  • 时间:2022-03-03 03:44 编辑: 来源: 阅读:
  • 扫一扫,手机访问
摘要:c# 获取网页中指定的字符串信息的实例代码
[u]复制代码[/u] 代码如下:
       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();          }
  • 全部评论(0)
联系客服
客服电话:
400-000-3129
微信版

扫一扫进微信版
返回顶部