-1

How do i make my script google something in my default browser

Example:

a = input("What to google? ")
google(a)
#this should google the input in default browser

Thanx in advance!

2
  • I want to search for a specific thing in google not open a url Commented Apr 30, 2021 at 13:50
  • 2
    That's just opening a specific URL on google.com, isn't it? Commented Apr 30, 2021 at 13:52

2 Answers 2

2

If it's something fairly simple to google:

import webbrowser
a = input("What to google? ")

webbrowser.open('https://www.google.com/search?q={}'.format('+'.join(a.split())))

OR

import webbrowser
a = input("What to google? ")

webbrowser.open('https://www.google.com/search?q={}'.format(a.replace(' ', '+')))
Sign up to request clarification or add additional context in comments.

Comments

-4

For searching in google, let's say we want to search 'python program for windows'.

The url will be https://www.google.com/search?q=python+program+for+windows. This shows that the space should be replaced with +

Here's the code:

import os
def google(a):
    d = "https://google.com/search?q="
    a = a.replace(' ','+')
    os.system("start " + d + a)

a = input("what to google? ")
google(a)
print(a + " googled...")

4 Comments

start only really works on Windows.
Exactly what i wanted! thanx and it also opens in default browser
@JoachimSauer I am in windows so it worked for me
@BartholoMew: you didn't specify that you're on Windows and Questions/Answers should be useful for other users in the future too. IMO the answer by RMRiver is much more useful and shorter.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.