16-http编程获取网站的标题
来源:互联网 发布:2015雾霾数据统计图 编辑:程序博客网 时间:2024/06/14 09:14
using System;using System.Collections.Generic;using System.Linq;using System.Net;using System.Windows;using System.Windows.Controls;using System.Windows.Documents;using System.Windows.Input;using System.Windows.Media;using System.Windows.Media.Animation;using System.Windows.Shapes;using Microsoft.Phone.Controls;using System.IO;namespace PhoneApp1{ public partial class MainPage : PhoneApplicationPage { // 构造函数 public MainPage() { InitializeComponent(); Loaded += new RoutedEventHandler(MainPage_Loaded); } void MainPage_Loaded(object sender, RoutedEventArgs e) { //创建对象 WebClient webClient = new WebClient(); //创建URi webClient.OpenReadAsync(new Uri("http://www.baidu.com")); //调用监听事件 webClient.OpenReadCompleted += new OpenReadCompletedEventHandler(webClient_OpenReadCompleted); getTitle(); } void webClient_OpenReadCompleted(object sender, OpenReadCompletedEventArgs e) { using (StreamReader reader = new StreamReader(e.Result)) { String content = reader.ReadToEnd(); int begin = content.ToString().IndexOf("<title>"); int end = content.ToString().IndexOf("</title>"); textBox1.Text = content.ToString().Substring(begin+7,end-begin-7); } } //获取title信息 private void getTitle() { String uri = "http://www.baidu.com"; HttpWebRequest request = (HttpWebRequest)HttpWebRequest.Create(uri); IAsyncResult result = request.BeginGetResponse(back,request); } private void back(IAsyncResult result) { //获取异步操作返回的信息 HttpWebRequest request = (HttpWebRequest)result.AsyncState; //结束对Internet资源的异步请求 WebResponse response = request.EndGetResponse(result); using(Stream stream=response.GetResponseStream()) using (StreamReader reader = new StreamReader(stream)) { string contents = reader.ReadToEnd(); int begin = contents.ToString().IndexOf("<title>"); int end = contents.ToString().IndexOf("</title>"); //切换到UI线程进行显示,此线程不同于UI线程 Dispatcher.BeginInvoke(() => { textBox2.Text = contents.ToString().Substring(begin + 7, end - begin - 7); }); } } }}
0 0
- 16-http编程获取网站的标题
- 获取网站标题
- Android WebView获取网站标题
- PHP 编程获取网站的 Alexa 排名
- 获取网页的标题
- JSP页面获取网站的协议类型(http或https)
- http://codepad.org/ 一个可以在线编程编译的网站
- UIWebView获取网页的标题
- [Mac OS X Cocoa编程]如何获取其他应用程序的窗体标题以及相关信息?
- 网站的标题定位的重要性
- 网站标题(title)SEO优化的重要性
- 浅谈网站标题对SEO的影响
- 怎么写好网站的标题
- asp.net网站top标题的代码
- 网站的页面标题有讲究
- 网站优化常见的几个标题
- 网站建设中标题关键字的写法
- 网站建设:三大标题的设置
- opentaps--windows下安装的一些问题
- Android平台最新开发技术发展和更新的介绍
- C++队列之动态分配数组
- 高德地图android sdk 地图显示和定位 基本使用方法
- jQuery选择器总结
- 16-http编程获取网站的标题
- 再玩Go
- 安卓开发 TabActivity切换
- 数组操作
- Oracle错误小记
- java简单工厂设计模式
- 1000内的阶乘以及大数阶乘相关知识链接
- 如何确认microsoft query已经安装
- 解决问题的函数