Prepare a string for Google Ajax Search?

I have strings such as

["Tabula Rasa", "façade", "DJ Tiësto"]

I'm accessing Google Ajax API in Python using the base url:

base = 'http://ajax.googleapis.com/ajax/services/search/web'
   '?v=1.0&q=%s'

I'm having issues using these strings plain and noticed I have to transform certain characters,

eg. "Tabula Rasa" -->  "Tabula%20Rasa"

But I have a huge list of these strings and I do not know of a way I can automatically prepare these string for the URL query.

Any help would be very much appreciated.

Answers


What you're looking for is urllib.quote():

>>> urllib.quote("Tabula Rasa")
'Tabula%20Rasa'

The non-ASCII strings may need to be recoded into the encoding expected by the Google AJAX API, if you don't have them in the same encoding already.


Need Your Help

How to document a function returned by a function using JSDoc

javascript jsdoc jsdoc3

In the code below, I am using JSDoc for parameter documentation.

Android client set input message to textview

android sockets client

I am new to android and java programming and I am trying to program a server client connection.

About UNIX Resources Network

Original, collect and organize Developers related documents, information and materials, contains jQuery, Html, CSS, MySQL, .NET, ASP.NET, SQL, objective-c, iPhone, Ruby on Rails, C, SQL Server, Ruby, Arrays, Regex, ASP.NET MVC, WPF, XML, Ajax, DataBase, and so on.