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?
Asked
Active
Viewed 102 times
1
-
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 Q Open Wid Dec 29 '20 at 21:45
3 Answers
5
Sure. The standard library has the webbrowser
module.
import webbrowser
webbrowser.open("https://www.google.com/search?q=xkcd%20python")

AKX
- 152,115
- 15
- 115
- 172
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 Q Open Wid
- 2,225
- 2
- 18
- 34
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
- 2,091
- 2
- 6
- 24
-
No offense, but would *not* recommend using this. You have to install selenium using ``pip``. – new Q Open Wid Dec 29 '20 at 21:32
-
Fair enough. Just thought I'd point it out in case someone has selenium already. – The Pilot Dude Dec 29 '20 at 21:37