Advertisment

Yahoo Search Web Services

author-image
PCQ Bureau
New Update

Yahoo has given in to the long-standing demand of many developers and finally launched its Web services. The Yahoo Search Web Services allows developers to query Yahoo's search engine from different programming languages. Google has been providing this facility for quite some time now with the Google Web API. The Yahoo Search Web Services, however, differs significantly from

Google's.

Advertisment

For starters, Google's API is SOAP-based while Yahoo chose to go with REST. The Google API can be used only for Web search meaning that services such as Google News, Google Image Search etc. cannot be accessed via the API. Yahoo, however, allows developers to search five 'channels' of content-the regular Web search, Image search, Local search, News search and Video search. While Google restricts developers to 1000 queries a day, Yahoo offers a generous 5000 queries per day in each of the channels. Both, however, require you to register for access to the APIs and are free of cost. Let's see how it works. 

You can access these services at their respective URLs and obtain results by specifying your query as a parameter. The URLs of the various services are as below (at the time of writing this article). 

In addition to the query, you need to specify your application ID (visit http://developer.yahoo.net

to get one free). Then there are certain other parameters that depend on the service you're using. A list of various parameters that Web search supports/requires is given in Table 2.

Advertisment
Direct Hit!
Applies to: Developers 
USP:

Understand how to write code in ASP.NET to query various channels in Yahoo's search engine
Links:

www.developer.yahoo.net 

One thing to note here with the query parameter is that it can include the full search language like 'site:', which makes it quite powerful. Let's take an example to make things a bit clearer. 

Let's say you want to search for the word 'technology' on the site pcquest.com and you want to fetch results number 8 and 9. This is how your request URL may look like:

Advertisment

http://api.search.yahoo.com/WebSearchService/V1/webSearch?appid=YahooDemo&query=technology+site:pcquest.com&results=2&start=8 



Let's see what response do we get to the above request.





http://www.w3.org/2001/XMLSchema-instance
" xmlns="urn:yahoo:srch" xsi:schemaLocation="urn:yahoo:srch http://api.search.yahoo.com/WebSearchService/V1/WebSearchResponse.xsd

" totalResultsAvailable="778" totalResultsReturned="2" firstResultPosition="8">






Technology in 2001


...


https://www.pcquest.com/content/topstories/100120301.asp


...


1106294400


text/html





...


33788























PCQuest : Technology : Communicate Better with ADSL2


...


https://www.pcquest.com/content/technology/103020705.asp


...


1106294400


text/html





...


32446





























(Note: In the above results the actual values of Summary, ClickUrl and Url have been replaced by ellipsis (... ) due to space constraints.)

Advertisment
Table

1: URLs of various services
Service Request

URL
Web http://api.search.yahoo.com/WebSearchService/V1/webSearch 
Image http://api.search.yahoo.com/ImageSearchService/V1/imageSearch 
Local http://api.local.yahoo.com/LocalSearchService/V1/localSearch 
News http://api.search.yahoo.com/NewsSearchService/V1/newsSearch 
Video http://api.search.yahoo.com/VideoSearchService/V1/videoSearch 

Let's process these results to come out with a neat list of results for use on our website. We'll use ASP.NET for this example, but you can do the same just as easily in any other programming language, especially if it has libraries/functions that allow for easy processing of

XML.

<%@ Page Language="C#" %>



<%@ import Namespace="System.Xml" %>
























 






Advertisment

This code creates an unordered list of the form Title - URL of all results returned by the query. The same code can be adapted to search Yahoo News or any of the other channels with minor changes. 

Table

2: Parameters used by Web search
Parameter Value Description
appid string

(required)
The

application ID.
query string

(required)
The

query to search for.
type all

(default), any, or phrase
The

kind of search to submit: all returns results with all query terms. any

returns results with one or more of the query terms. phrase returns

results containing the query terms as a phrase.
results Integerdefault

10, max 50
The

number of results to return.
start Integer:

default 1
The

starting result position to return (1-based). The finishing position

(start + results - 1) cannot exceed 1000.
format all

(default), html, msword, pdf,

ppt, rss, txt, xls
Specifies

the kind of files to search for.
adult_ok no

value (default), or 1
Specifies

whether to allow results with adult content.
similar_ok no

value (default), or 1
Specifies

whether to allow multiple results with similar content
language string:

default en
The

language the results are written in.

The introduction of Yahoo Search Web Services is really a welcome step for developers and surely there are going to be many useful applications based on this in the near future.

Kunal Dua

Advertisment