Use the C # regular expression to obtain the Bing daily image address,

Source: Internet
Author: User

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

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.