0

I'm calling this url by passing query string parameter, i have to pass name parameter to details.py

Url is :

http://www.somesite.com/details.py?name=test

i tried using request but i can't get this parameter.

Code:

import requests
resp = requests.get('name')

2 Answers 2

1

requests is for performing http calls

To "get" the value from that string, you'd want urllib.parse module for parsing URIs

Getting a query parameter on the server-side would depend on what web framework you're using

Sign up to request clarification or add additional context in comments.

2 Comments

Thanks i'm not using any framework, i'm using python 3.6, how i will get current url and pass it to urlparse eg. parsed_url = urlparse(url)
I don't know what context your code runs in. Are you implementing a server? Or are you just a client? Or are you doing data analysis on a collection of urls? What do you mean "get the url"? As far as you've shown, you already have that as a string.
1

Use urllib to parse urls;

from urllib.parse import urlparse
from urllib.parse import parse_qs

url = 'http://www.somesite.com/details.py?name=test'

# parse the url 
parsed_url = urlparse(url)

# parse the request's parameters
parsed_params = parse_qs(parsed_url.query)

# get the 'name' parameter 
name = parsed_params['name'][0]

print(name)
>>> 'test'

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.