Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

Python – How to search in google without typing url

I tried to take the input from the user, copy it, and then open google and paste the input.

this is my code:

import webbrowser

import pyperclip

question = input("search for: ")

pyperclip.copy(question)

url = 'http://www.google.com/'

chrome_path = 'C:/Program Files (x86)/Google/Chrome/Application/chrome.exe %s'

webbrowser.get(chrome_path).open(url) 

pyperclip.paste()

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

>Solution :


import webbrowser


question = input("search for: ")
question = question.replace(' ', '+') # replace <space> with +


url = 'https://www.google.com/search?q=' + question # google search url

chrome_path = 'C:/Program Files (x86)/Google/Chrome/Application/chrome.exe %s'

webbrowser.get(chrome_path).open(url) 

You don’t need to paste the url.
When you search a url something like "hello world" in the browser
the url is
enter image description here

The spaces are replaced with + sign.

Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading