Skip to content

Instantly share code, notes, and snippets.

@ColtonPhillips
Created July 6, 2014 06:38
Show Gist options
  • Save ColtonPhillips/ffe0874b9a785953dd20 to your computer and use it in GitHub Desktop.
Save ColtonPhillips/ffe0874b9a785953dd20 to your computer and use it in GitHub Desktop.
What if you could turn an arbitrary text into a google search?
#TODO: what about a string with < or > ? what about with </a> ? etc
#https://www.google.ca/#q=hat+%22stand+man+'dog'+%22
# hat "stand man 'dog' "
my_string = "hat \"stand man 'dog' \""
print("String:")
print(my_string)
google_string = my_string.replace('"',"%22").replace(" ","%20")
print("Google String:")
print(google_string)
google_search = "https://www.google.com/search?q=" + google_string
print("Google Search:")
print(google_search)
my_http_string = '<div>\n\t<a href="' + google_search + '" target="_blank" >\n\t\t' + my_string + '\n\t</a>\n</div>'
print("HTTP:")
print(my_http_string)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment