1

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()
hostingutilities.com
  • 8,894
  • 3
  • 41
  • 51
Basel
  • 17
  • 1
  • 3
  • What do you mean by `without typing url` ? You don't want to type it manually or you don't to change the adress bar "by yourself" (by letting the webpage doing it for example) – Marius ROBERT Jun 02 '22 at 11:36
  • for example "search for best programming language". Here I don't write any url only question> – Basel Jun 02 '22 at 12:04

1 Answers1

2

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.

  • I'm not sure but OP `without typing url` maybe mean that he don't want to edit the URL – Marius ROBERT Jun 02 '22 at 11:35
  • to achieve the same thing, this would be better way. Then trying to find the input box and pasting the text –  Jun 02 '22 at 11:36