0

I'm working on parsing name/value pairs in Python 3.

I want to send name/value pairs to my script to simulate them coming from a web form.

I'm trying something like:

python myscript.py?v1=a&v2=b&v3=c

but that doesn't work. I get the error:

python: can't open file 'C:\\py\\myscript.py?v1=a': [Errno 22] Invalid argument
'v2' is not recognized as an internal or external command,
operable program or batch file.
'v3' is not recognized as an internal or external command,
operable program or batch file.

Is there a way to do what I'm asking?

Shawn
  • 3,031
  • 4
  • 26
  • 53

1 Answers1

0

You can send data as name-value pairs using the "requests" library in Python. You can make a POST request to the URL where the form would normally be submitted and include the data in a dictionary as the data parameter in the request. Here's an example:

import requests

url = "https://www.example.com/form-submit"
data = {
    "field_name_1": "value_1",
    "field_name_2": "value_2",
    "field_name_3": "value_3"
}

response = requests.post(url, data=data)

print(response.text)

In this example, data is a dictionary containing the name-value pairs that you want to send in the request. The requests.post function makes a POST request to the specified URL and includes the data in the request. The response from the server is stored in the response variable, and you can access the response text using response.text.

Shawn
  • 3,031
  • 4
  • 26
  • 53