1

I am using the following code to parse an URL:

url3 = "https://flyingcar.org/dfr/?d=34u&f=56&dossier=ZT18174&document=US1234567&docs='US1','US2','US3'#{'para1':'UK','para2':'Ireland'}"

parsed = urlparse(url3)
print('url:\n',url3)

captured_values = parse_qs(parsed.query)
print(f'parse_qs of querys: {captured_values} type: {type(captured_values)}')
print(f'here the parameters: {parsed.fragment} type: {type(parsed.fragment)}')

It all work kind of fine. What I don't know is how to build the URL in order to pass a list of variables, i.e. in the above example the results are:

url:
 https://flyingcar.org/dfr/?d=34u&f=56&dossier=ZT18174&document=US1234567&docs='US1','US2','US3'#{'para1':'UK','para2':'Ireland'}
parsed.params=''
parsed.query="d=34u&f=56&dossier=ZT18174&document=US1234567&docs='US1','US2','US3'"
parsed.fragment="{'para1':'UK','para2':'Ireland'}"
parse_qs of querys: {'d': ['34u'], 'f': ['56'], 'dossier': ['ZT18174'], 'document': ['US1234567'], 'docs': ["'US1','US2','US3'"]} type: <class 'dict'>
here the parameters: {'para1':'UK','para2':'Ireland'} type: <class 'str'>

I would like to that in the query the variable docs contains a list and not a string, like:

'docs': ['US1','US2','US3']
#instead of:
'docs': ["'US1','US2','US3'"]

How should I build the URL?

0

1 Answer 1

1

You can use this snippet after parsing URL:

for i in captured_values:
    captured_values[i]=captured_values[i][0].replace("'","").split(",")

print(captured_values)

output:

{'d': ['34u'], 'f': ['56'], 'dossier': ['ZT18174'], 'document': ['US1234567'], 'docs': ['US1', 'US2', 'US3']}

Although I do not feel good about replacing it, but you can use the solution

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

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.