开发者

Prepare a string for Google Ajax Search?

开发者 https://www.devze.com 2022-12-16 20:43 出处:网络
I have strings such as [\"Tabula Rasa\", \"façade\", \"DJ Tiësto\"] I\'m accessing Google Ajax API in Python using the base url:

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 = '开发者_JAVA技巧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.


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.

0

精彩评论

暂无评论...
验证码 换一张
取 消