-1

I need to convert any string to a google search link. For example:

"google search link"  -> https://www.google.com/search?q=google+search+link&oq=google+search+link&aqs=chrome..69i57j0l9.3500j0j4&sourceid=chrome&ie=UTF-8

Is there any python library or function for this conversion.

GMaster
  • 39
  • 3

2 Answers2

1

An easy solution for your sample string:

my_str = "google search link"
out_link = "https://www.google.com/search?q=" + '+'.join(my_str.split(' '))

You might be interested in deleting/handling special characters too

ALai
  • 739
  • 9
  • 18
1
import urllib.parse; 
quary = "how to Convert string to google search link in python"
safe_string = urllib.parse.quote_plus(quary)
print("https://www.google.com/search?q="+safe_string)

How to urlencode a querystring in Python?

Vaisakh K M
  • 105
  • 1
  • 7