我如何通过 python 脚本将某些内容 google 放入我的浏览器?

How can i google something into my browser through python script?

如何在我的默认浏览器中制作脚本google

示例:

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

提前致谢!

为了在 google 中搜索,假设我们要搜索 'python program for windows'。

url 将是 https://www.google.com/search?q=python+program+for+windows。这表明 space 应该替换为 +

代码如下:

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...")

如果google相当简单:

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

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

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

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