How to collect all the image resources on the page by asp.net
This article mainly explains "how asp.net collects all the image and picture resources on the page". The content in the article is simple and clear, and it is easy to learn and understand. Please follow the editor's train of thought to study and learn "how to collect all the image and picture resources on the page by asp.net".
/ / download all the pictures under the specified URL / public class WebPageImage {/ get all the pictures in the web page / web address / web page code, empty automatic judgment / all pictures display code public string getImages (string url, string charSet) {string s = getHtml (url, charSet) Return getPictures (s, url);} / URL / all images code public string getImages (string url) {return getImages (url, ");} string doman (string url) {Uri u = new Uri (url); return u.Host } / obtain the encoding of the web page / website address / the encoding of the target web page. If null or "" is passed in, the encoding of the web page / string getHtml (string url, string charSet) {WebClient myWebClient = new WebClient () is automatically analyzed. / / create WebClient instance myWebClient / / Note: / / whether some web pages may come down, there are various reasons, such as the need for cookie, coding problems, etc. / / this requires specific analysis of specific problems, such as adding cookie / / webclient.Headers.Add ("Cookie", cookie) in the header; / / this may require some overloading methods. Just write as needed / / get or set the network credentials used to authenticate requests to Internet resources. MyWebClient.Credentials = CredentialCache.DefaultCredentials; / / if the server wants to verify the user name, the password / / NetworkCredential mycred = new NetworkCredential (struser, strpassword); / / myWebClient.Credentials = mycred; / / downloads data from the resource and returns a byte array. (add @ because there is a "/" symbol in the middle of the URL) byte [] myDataBuffer = myWebClient.DownloadData (url); string strWebData = Encoding.Default.GetString (myDataBuffer); / / get the page character encoding description information Match charSetMatch = Regex.Match (strWebData, "