This code demonstrates how you can use the Bing XML api to generate Bing search results for your Ruby (and Ruby on Rails) application
Before you can run this code, you need to register as a Bing developer and create an AppId for your application. This is quick and completely free. See http://www.bing.com/developers/ for more information.
require 'net/http' require 'rexml/document' appId = "1234567890123456789012345678901234567890" # Paste your real AppId here! search = "Lewis Hamilton" uri = URI.parse("http://api.search.live.net/xml.aspx?AppId=#{appId}&sources=Web&query=#{URI.escape(search)}") xml_response = Net::HTTP.get_response(uri).body doc = REXML::Document.new(xml_response) doc.elements.each("SearchResponse/web:Web/web:Results/web:WebResult") do |result| p result.get_elements("web:Title")[0].text p result.get_elements("web:Description")[0].text p result.get_elements("web:Url")[0].text p result.get_elements("web:DisplayUrl")[0].text p result.get_elements("web:DateTime")[0].text p "--------------------------------------------------" end
Related: Bing: Performing a basic web search over SOAP with the new Bing API 2.0
About
We are a small British company that produces business-oriented software and solutions. These articles are a product of our daily work - information that we think might be useful to share. We hope you find them useful.
Our Software
These are some of our products. Several are open source, some are web-based and others are proprietary:
Categories
- .NET (10)
- Apple (2)
- Business (5)
- CSS (1)
- HTML (2)
- Innovation (4)
- Java (4)
- Javascript (1)
- Leadership (1)
- MySQL (2)
- Oracle (6)
- Postgres (1)
- Programming (5)
- Rails (4)
- Ruby (10)
- SQL Server (9)
- Subversion (1)
- Web (5)
- Windows Server (2)
Archives
- July 2010 (2)
- September 2009 (5)
- August 2009 (1)
- July 2009 (12)
- June 2009 (16)
- May 2009 (3)