پیدا کردن یک رشته در صفحه وب - کد سی شارپ

// Locate string on webpage private bool SearchPage(string URL, string StrToLocate) { StreamReader SR; WebResponse Resp ; WebRequest MyWebRequest; string PageStr; MyWebRequest = WebRequest.Create(URL) ; MyWebRequest.Timeout = 10000 ; try { Resp = MyWebRequest.GetResponse() ; SR = new StreamReader(Resp.GetResponseStream()) ; PageStr = SR.ReadToEnd() ; SR.Close() ; PageStr = PageStr.ToUpper(); if ( PageStr.IndexOf(StrToLocate.ToUpper(), 0, PageStr.Length) != -1 ) return true; else return false; } catch ( WebException wex ) { if (wex.Status == WebExceptionStatus.Timeout) Response.Write("The request has timed out!") ; else Response.Write("There was some exception: " + wex.Message ) ; return false; } }
/ 0 نظر / 22 بازدید