

Study with the several resources on Docsity
Earn points by helping other students or get them with a premium plan
This page cannot be seen from the preview
Don't miss anything!


The Google API There are many Python libraries around that do interesting things. Some allow you to call web services like the one Google provides. The pygoogle library is one such library. Here's a simple example that uses the Python's pygoogle library. import google google.setLicense("H2deIvNQFHI9ilswRXR1h1+7IqnD7Pp4") data = google.doGoogleSearch('wolber') # print data.results[0].URL print data.results[0].title The ‘doGoogleSearch’ function returns a complex object. ‘data’ catches it. It has one field called results, which is itself a list of objects each having a URL and a title (and some other things). For a full description of the the pygoogle Google API, see: http://pygoogle.sourceforge.net/dist/doc/index.html As the API documentation shows, doGoogleSearch returns an object of type SearchReturnValue. Here's the text from the API: Returns: the search results encapsulated in an object (type=SearchReturnValue) SearchReturnValue has two fields: meta: SearchResultsMetaData results: list of SearchResult
‘ meta ’ is the name of the first part. Its type is ‘searchResultsMetaData’. It contains information such as the total number of results for the query: directoryCategories: list of categories for the search results documentFiltering: is duplicate page filtering active? endIndex: index of the last result returned (zero-based) estimatedTotalResultsCount: estimated results for this query. estimateIsExact: is estimatedTotalResultsCount an exact value? searchComments: human-readable informational message searchQuery: search string that initiated this search searchTime: total search time, in seconds searchTips: human-readable informational message on how to better use Google. startIndex: index of the first result returned (zero-based) ‘ results ’ is the list of search results, as used in the example above. It contains a list of SearchResult. A SearchResult has: cachedSize: size of cached version of this result, (KB) directoryCategory: Open Directory category information directoryTitle: Open Directory title of this result (or blank) hostName: used when filtering occurs relatedInformationPresent: is the "related:" keyword supported? snippet: snippet showing query context (HTML summary: Open Directory summary for this result (or blank) title: title (HTML) URL: URL You access the fields of an object using '.', e.g., data = google.doGoogleSearch('wolber') print data.meta.estimatedTotalResultsCount In-Class Problem