Hi,
I can use the syntax below to obtain the variable with the value of a query through a url, exemplifying prints
ws_qty = environ['QUERY_STRING']
Screen Print -> variable=value
How do I print on the screen only the value ?
(Mar-07-2020, 12:58 AM)JohnnyCoffee Wrote: [ -> ]How do I print on the screen only the value ?
You need to parse the query string manually, e.g.
print(ws_qty.split('=')[1])
, or use
urllib.parse.parse_qs
utility function.
(Mar-07-2020, 09:01 AM)scidam Wrote: [ -> ] (Mar-07-2020, 12:58 AM)JohnnyCoffee Wrote: [ -> ]How do I print on the screen only the value ?
You need to parse the query string manually, e.g. print(ws_qty.split('=')[1])
, or use
urllib.parse.parse_qs
utility function.
Using syntax :
ws_qty.split('=')[1]
, I managed to get the value of the variable, thanks.
Using parse_qs got
{'variable': ['value']}
, How do I access the value of the variable ?
everything is quite confusing - your setup and the data you work with and what you try to get
reading something from [what looks like] environment variable (how it did get there), yet asking about "obtain the variable with the value of a query through a url"
IMHO you need to provide more information...
If it is some URL and you want to parse it - did you check urllib.parse?
OK I saw you sort of use it
(Mar-07-2020, 01:48 PM)JohnnyCoffee Wrote: [ -> ] (Mar-07-2020, 09:01 AM)scidam Wrote: [ -> ] (Mar-07-2020, 12:58 AM)JohnnyCoffee Wrote: [ -> ]How do I print on the screen only the value ?
You need to parse the query string manually, e.g. print(ws_qty.split('=')[1])
, or use
urllib.parse.parse_qs
utility function.
Using syntax : ws_qty.split('=')[1]
, I managed to get the value of the variable, thanks.
Using parse_qs got {'variable': ['value']}
, How do I access the value of the variable ?
I managed to solve the problem of parse_qs by converting to dictionary, see the syntax:
ws_value = dict(parse_qsl(ws_arg))
ws_value['search']
Result, Literal value