1

On Python, is there a way you can to bring up a page showing results for a query? I don't want to get a list containing the URLs from google search; I want the program to open up a new tab showing the results from a google search. Is there any way to do this?

anaconda
  • 21
  • 3
  • Are you saying you want the script to run a google search in a new browser tab? If so does [this](https://stackoverflow.com/questions/4216985/call-to-operating-system-to-open-url) help? Or are you trying to generate a whole new page as opposed to just opening a URL? If so do you have any experience at all with creating websites or webpages via Python? – Random Davis Dec 29 '20 at 21:20
  • If my answer helped you get the solution, you can accept it by clicking the gray checkmark next to it – new QOpenGLWidget Dec 29 '20 at 21:45

3 Answers3

5

Sure. The standard library has the webbrowser module.

import webbrowser

webbrowser.open("https://www.google.com/search?q=xkcd%20python")
AKX
  • 123,782
  • 12
  • 99
  • 138
2

If you want to open up a new tab in a browser, you can use webbrowser:

import webbrowser
webbrowser.open_new_tab(url)

where url is the URL you're aiming for. The documentation says:

Open url in a new page (“tab”) of the default browser, if possible, otherwise equivalent to open_new().

new QOpenGLWidget
  • 1,744
  • 2
  • 15
  • 28
1

Try using selenium:

from selenium import webdriver

query = input("What Would You Like To Search: ")
words = query.replace(" ", "+")

webdriver = webdriver.Chrome()
webdriver.get(f"https://www.google.com/search?client=opera&q={words}&sourceid=opera&ie=UTF-8&oe=UTF-8")
The Pilot Dude
  • 1,798
  • 2
  • 4
  • 22