Access the Yahoo! Search APIs using pYsearch

pYsearch is an open-source Python library for accessing the Yahoo! Search APIs written by Leif Hedstrom. This overview covers version 2.0 which can be downloaded from SourceForge.

Basic usage of pYsearch involves creating a search query object and then executing it to get back a results object. Here's an example showing how to search Yahoo! News:

>>> from import NewsSearch
>>> srch = NewsSearch('YahooDemo', query='kittens')
>>> info = srch.parse_results()
>>> info.total_results_available
>>> info.total_results_returned
>>> info.first_result_position
>>> for result in info.results:
...     print "'%s', from %s" % (result['Title'], result['NewsSource'])
'Cats, kittens on sale for a discount at Winnipeg shelter', from CBC Manitoba
'Singapore playwright Ovidia Yu', from Radio Singapore International
'News Feature', from Rye and Battle Today

The standard query returns the first 10 results. To retrieve the next 10, specify a start parameter.

>>> srch = NewsSearch('YahooDemo', query='kittens', start=11)
>>> info = srch.parse_results()
>>> info.total_results_available
>>> info.first_result_position

Likewise, you can use a results=20 parameter to change the number of results retrieved at a time (up to a maximum of 50). Other NewsSearch parameters reflect the request parameters listed in the News Search API documentation.

pYsearch includes classes for almost all of the Search APIs. You should consult the pYsearch online documentation for details of which class corresponds to which API.