1

I am trying to take multiple URL's separated by comma and put them in list in python.

I tried:

url = request.GET.get('url').split(',')  #accept url seperated by comma
data= []
data.append(requests.get(url).content)

The above code did not work for obvious reasons. How can I accept multiple url separated by comma using request.GET

1
  • url is your list. Commented Feb 26, 2020 at 11:52

2 Answers 2

1

url is a list of URLs. Hence you can perform a mapping. For example with list comprehension:

urls = request.GET.get('url').split(',')
data = [requests.get(url).content for url in urls]
Sign up to request clarification or add additional context in comments.

Comments

0

To extend Willem's answer a step further, you can also do the same thing with a dictionary. This is useful if you will want to use the url as a key to retrieve the content later.

urls = request.GET.get('url').split(',')
data = {url: requests.get(url).content for url in urls}

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.