-1

If I have a variable, lets say, favorite singer, I want to open the web browser and search for that singer. I was planning to use the following code to open Google, but how can I make the users input become the actual search itself?

webbrowser.open('www.google.com')
1
  • I tried the code from that link and it didn't work. Commented Jun 28, 2013 at 12:43

1 Answer 1

2

To pre-populate the searchbox, use:

import webbrowser
from urllib import urlencode

webbrowser.open('http://www.google.com/?' + urlencode({'q': 'the quick brown fox'}))
Sign up to request clarification or add additional context in comments.

4 Comments

@Haidro you spotted my deliberate mistake - well done
Thanks Jon. I want to use GPS coordinates and put them into google maps. So how would I do that? Here is some code (which doesn't work) webbrowser.open('www.google.com/maps/',longitude_ref) I have longitude_ref stored as a variable, but I want to use it to search.
@user2519572 Using a comma will add a space. Simply, use +. Or even .format()
@user2519572 you'll need to find the right url from experimenting with your browser, and then opening that...

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.