类的代码:
1 using System; 2 using System.Data; 3 using System.Configuration; 4 using System.Net; 5 using System.IO; 6 using System.Text; 7 using System.Collections.Generic; 8 using System.Text.RegularExpressions; 9 using System.Threading; 10 using System.Web; 11 using System.Web.UI.MobileControls; 12 /// <summary> 13 /// 网页类 14 /// </summary> 15 public class WebPage 16 { 17 #region 私有成员 18 private Uri m_uri; //url 19 private List<Link> m_links; //此网页上的链接 20 private string m_title; //标题 21 private string m_html; //HTML代码 22 private string m_outstr; //网页可输出的纯文本 23 private bool m_good; //网页是否可用 24 private int m_pagesize; //网页的大小 25 private static Dictionary<string, CookieContainer> webcookies = new Dictionary<string, CookieContainer>();//存放所有网页的Cookie 26 27 #endregion 28 29 #region 属性 30 31 /// <summary> 32 /// 通过此属性可获得本网页的网址,只读 33 /// </summary> 34 public string URL 35 { 36 get 37 { 38 return m_uri.AbsoluteUri; 39 } 40 } 41 42 /// <summary> 43 /// 通过此属性可获得本网页的标题,只读 44 /// </summary> 45 public string Title 46 { 47 get 48 { 49 if (m_title == "") 50 { 51 Regex reg = new Regex(@"(?m)<title[^>]*>(?<title>(?:\w|\W)*?)</title[^>]*>", RegexOptions.Multiline | RegexOptions.IgnoreCase); 52 Match mc = reg.Match(m_html); 53 if (mc.Success) 54 m_title = mc.Groups["title"].Value.Trim(); 55 } 56 return m_title; 57 } 58 } 59 public string M_html 60 { 61 get 62 { 63 if (m_html == null) 64 { 65 m_html = ""; 66 } 67 return m_html; 68 } 69 } 70 /// <summary> 71 /// 此属性获得本网页的所有链接信息,只读 72 /// </summary> 73 public List<Link> Links 74 { 75 get 76