Python Forum
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Get value of a query ?
#1
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 ?
Reply
#2
(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.
Reply
#3
(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 ?
Reply
#4
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
If you can't explain it to a six year old, you don't understand it yourself, Albert Einstein
How to Ask Questions The Smart Way: link and another link
Create MCV example
Debug small programs

Reply
#5
(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
Reply


Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020