What is the syntax for adding a GET parameter to a URL?

若如初见. 提交于 2020-01-01 01:11:29

问题


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?


回答1:


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&param2=seven.

If you want to generate the param1=7&param2=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&param2=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&param2=seven'.




回答2:


I am fairly certain this has been asked many times before, but the query parameters start with ? and are separated by & like so:

http://www.site.com/script.php?key=value&var=num




回答3:


http://www.foo.com/somepath?keyword1=value1&keyword2=value2&keyword3=value3



来源:https://stackoverflow.com/questions/5767464/what-is-the-syntax-for-adding-a-get-parameter-to-a-url

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!