-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 Answers2

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(' ', '+')))
RMRiver
  • 625
  • 1
  • 5
  • 19
-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...")
Joachim Sauer
  • 302,674
  • 57
  • 556
  • 614
Pear
  • 351
  • 2
  • 12