Microsoft's Bing search engine homepage provides some interesting pictures every day. The following uses regular expressions to obtain the address of the picture. It is a good picture material whether it is on the mobile app or on the website, and it is updated every day, which is very good.
First, access Microsoft's API. The address returns xml text. After obtaining the xml text, use a regular expression to match the content in the url node, and add a Bing homepage link to get the real URL of the image. Below is the complete code to get the URL.
string InfoUrl = "/?idx=0&n=1"; HttpWebRequest request = (HttpWebRequest)(InfoUrl); = "GET"; = "text/html;charset=UTF-8"; string XmlString; using (HttpWebResponse response = (HttpWebResponse)()) { Stream myResponseStream = (); using (StreamReader myStreamReader = new StreamReader(myResponseStream, Encoding.UTF8)) { XmlString = (); } } // Define regular expressions to match tagsRegex regImg = new Regex("<Url>(?<imgUrl>.*?)</Url>", ); // Search for matching stringsMatchCollection matches = (XmlString); // Get the match liststring ImageUrl = "" + matches[0].Groups["imgUrl"].Value; background_image.Src = ImageUrl;
The above is what the editor introduced to you to use C# regular expressions to obtain the Bing Daily Picture Address. I hope it will be helpful to everyone. If you have any questions, please leave me a message and the editor will reply to everyone in time. Thank you very much for your support for my website!