For example username
and password
in
r = requests.post( loginUrl, data = {'username':'myuser', 'password':'mypw'} )
are from attribute name
on the web site element. The information to post
is given in parameter data
with a dictionary.
It has a key username
with a value myuser
. The key username
is taken from an element on a website with attribute name
, means the key is taken from a key-value. By default requests
select attribute name
for the key.
To clarify this here is a html code snippet:
<form name="login" id="form1" method="post" action="http://mylogin.net">
Username: <input name="username" id="input1" type="text" /><br/>
Password: <input name="password" id="input2" type="password" /><br/>
<input type="submit" value="OK" />
</form>
I prefer to use the id
attribute as key because it is unique on the web page.
How can I select attribute id
instead of default name
to get the key for the post in requests
, so I can use
r = requests.post( loginUrl, data = {'input1':'myuser', 'input2':'mypw'} ) ?