How to pick between two forms using python requests library? -
i trying use requests library submit post request website contains 2 forms. site https://itsapps.unc.edu/dir/dirsearch/view.htm , trying access advanced search form.
the html of forms looks like:
... <div id="basicsearch" class="yui-hidden"> <form onsubmit="return false;" method="post" accept-charset="utf-8"> ... </form> </div> <div id="advancedsearch"><!-- advanced search --> <form onsubmit="return false;" method="post" accept-charset="utf-8"> <table class="section"> <tr> <td colspan="2"><label for="affiliation">search ...
how go doing this? there way specify form id/name? right have is:
url = 'https://itsapps.unc.edu/dir/dirsearch/search' form_data = {'affiliation':'students', 'firstname':'anthony'} response = requests.post(url, data=form_data) print response.text
because advanced search option has affiliation drop down, assumed having within form parameter automatically select form matches params, output not changes when remove affiliation parameter form_data.
note, form data seen when checking developer tools network info basic search is:
searchstring=anthony
and advanced search is:
affiliation=student&firstname=anthony&lastname=&email=&pid=&onyen=
you have post https://itsapps.unc.edu/dir/dirsearch/search
, json returned:
in [1]: data = { ...: "firstname": "laurel", ...: "lastname": "foote-hudson"} in [2]: in [2]: r = requests.post("https://itsapps.unc.edu/dir/dirsearch/search", data=data) in [3]: print(r.json()) [{u'uncreversedisplayname': u'foote-hudson, laurel', u'telephonenumber': u'xxxxxxxxxxxxxxx', u'edupersonnickname': u'laurel', u'uncpreferredsurname': u'foote-hudson', u'sn': u'foote-hudson', u'spid': u'240a0d7c1534aa3a', u'mail': u'xxxxxxxxxxx', u'givenname': u'laurel'}
you can see post form fields using chrome or firefox:
the fields don't supply empty.
Comments
Post a Comment