html解析:请求网址并解析返回的html来源: 发布时间:星期四, 2009年2月12日 浏览:107次 评论:0
目 ![]() ![]() ![]() ![]() ![]() 1 、向远程服务器Post数据 public ![]() ![]() ![]() ![]() { info = \"\"; CookieContainer cc = ![]() ![]() HttpWebRequest request = WebRequest.Create(url) as HttpWebRequest; request.CookieContainer = cc; request.Method = \"POST\"; request.ContentType = \"application/x-www-form-urlencoded\"; Stream requestStream = request.GetRequestStream ![]() ![]() ![]() ![]() requestStream.Write( ![]() ![]() requestStream.Close ![]() HttpWebResponse response = request.GetResponse ![]() Uri responseUri = response.ResponseUri; Stream receiveStream = response.GetResponseStream ![]() Encoding encode = ![]() StreamReader readStream = ![]() ![]() ![]() info = result; ![]() }2、解析返回 ![]() ![]() public ClassInfo ![]() ![]() { ArrayList ar = ![]() ![]() ArrayList arr = ![]() ![]() ![]() Regex regtable = ![]() Match ma = regtable.Match(html); while (ma.Success) { ![]() ![]() { arr.Add(HttpUtility.HtmlDecode(ma.Value)); } ma = ma.NextMatch ![]() } for ( ![]() ![]() { table = arr[i]. ![]() ![]() } Regex reg = ![]() Match m = reg.Match(table); while (m.Success) { ![]() ![]() { ar.Add(HttpUtility.HtmlDecode(m.Value)); } m = m.NextMatch ![]() } ClassInfo ![]() ![]() ![]() for ( ![]() ![]() ![]() { ci[i] = ![]() ![]() ci[i].RegisterDate = (ar[i * 8 + 0]). ![]() ![]() ci[i].LoginDate = (ar[i * 8 + 1]). ![]() ![]() ci[i].LogoutDate = (ar[i * 8 + 2]). ![]() ![]() ci[i].UseMin = ar[i * 8 + 3]. ![]() ![]() ci[i].ClassName = ar[i * 8 + 5]. ![]() ![]() ci[i].ClassType = ar[i * 8 + 6]. ![]() ![]() ci[i].Percent = ar[i * 8 + 7]. ![]() ![]() } ![]() } 3、定义ClassInfo类(课程类) ![]() public ![]() { Member Variables#region Member Variables protected ![]() protected ![]() protected ![]() protected ![]() protected ![]() ![]() protected ![]() ![]() protected ![]() //protected ![]() #endregion Constructors#region Constructors public ClassInfo ![]() public ClassInfo( ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() { this._loginDate = loginDate; this._logoutDate = logoutDate; this._registerDate = registerDate; this._useMin = useMin; this._ ![]() ![]() this._ ![]() ![]() this._percent = percent; } #endregion Public Properties#region Public Properties // public ![]() // { // get{ ![]() // ![]() // } public ![]() { get { ![]() ![]() } public ![]() { get { ![]() ![]() } public ![]() { get { ![]() ![]() } public ![]() { get { ![]() ![]() } public ![]() { get { ![]() ![]() ![]() { ![]() throw ![]() ![]() ![]() _ ![]() } } public ![]() { get { ![]() ![]() ![]() { ![]() throw ![]() ![]() ![]() _ ![]() } } public ![]() { get { ![]() ![]() { ![]() throw ![]() ![]() ![]() _percent = value; } } #endregion } 0
相关文章读者评论发表评论 |