Use the C # regular expression to obtain the Bing daily image address,
The Bing search engine home page of Microsoft provides some interesting pictures every day. The following uses regular expressions to obtain the address of the picture. It is a good image material for both mobile apps and websites, and updated every day, 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 the Bing homepage link to obtain the real url of the image. The following is all the code for obtaining the URL.
String InfoUrl = "http://cn.bing.com/HPImageArchive.aspx? Idx = 0 & n = 1 "; HttpWebRequest request = (HttpWebRequest) WebRequest. create (InfoUrl); request. method = "GET"; request. contentType = "text/html; charset = UTF-8"; string XmlString; using (HttpWebResponse response = (HttpWebResponse) request. getResponse () {Stream myResponseStream = response. getResponseStream (); using (StreamReader myStreamReader = new StreamReader (myResponseStream, Encoding. UTF8) {XmlString = MyStreamReader. ReadToEnd () ;}// define a regular expression to match the tag Regex regImg = new Regex ("<Url> (? .*?) </Url> ", RegexOptions. ignoreCase); // search for the matched string MatchCollection matches = regImg. matches (XmlString); // get the match list string ImageUrl = "http://www.bing.com" + matches [0]. groups ["imgUrl"]. value; background_image.Src = ImageUrl;
Synchronously posted on my blog, use the C # regular expression to get the Bing daily image address