So today I started reading about the Bing API and I got myself an API key and I read through the basic instruction manual, which tells you how to get search results from the web through the Bing REST service. Its pretty straight forward, just get your own key though! But here is some sample code that does the trick and uses Linq to XML to process the results:
XDocument document = XDocument.Load("http://api.search.live.net/xml.aspx?Appid=&query=sushi&sources=web");
XElement root = document.Root;
XNamespace web = "http://schemas.microsoft.com/LiveSearch/2008/04/XML/web";
var searchItems = document.Descendants(web + "Results").SingleOrDefault();
IEnumerable testelem = from el in searchItems.Elements()
select el;
foreach (XElement myElem in testelem)
{
context.Response.Write(myElem.Value + "");
}
That is very easy!
Place your comment