I am using Python and Google App Engine.
I need to get access to certain webpage by adding some elements to the url.
What is the syntax for adding a GET parameter to a URL?
Asked
Active
Viewed 9.1k times
28

irenka
- 281
- 1
- 3
- 3
-
possible duplicate of [Add params to given URL in Python](http://stackoverflow.com/questions/2506379/add-params-to-given-url-in-python) – Ignacio Vazquez-Abrams Apr 23 '11 at 22:47
4 Answers
42
You put ?
in the end of the url. After the ?
you put var1=val1&var2=val2& ...
.
For example, if your raw url (without the get parameters) is http://www.example.com/ and you have two parameters, param1=7
and param2=seven
, then the full url should be:
http://www.example.com/?param1=7¶m2=seven.
If you want to generate the param1=7¶m2=seven
in python, you can use a parameter dictionary, like this:
import urllib
parameters = urllib.urlencode({'param1':'7', 'param2':'seven'})
The value of parameters
is 'param1=7¶m2=seven'
so you can append the parameters
string to a url like this:
raw_url = 'http://www.example.com/'
url = raw_url + '?' + params
Now the value of url
is 'http://www.example.com/?param1=7¶m2=seven'
.

snakile
- 52,936
- 62
- 169
- 241
7
I am fairly certain this has been asked many times before, but the query parameters start with ? and are separated by & like so:

jhocking
- 5,527
- 1
- 24
- 38
5
-
2I know this is 5 years old, but this answer isn't entirely correct. If somepath refers to a file, such as somepath.php, then that is fine. But, if it refers to foo.com/somepath/index.php, then the parameters won't work (at least in PHP), it needs to be foo.com/somepath/?keyword1... – Zachary Weixelbaum Sep 05 '16 at 12:37