d = {e['name']: e.get('value', '') for e in html_proc.find_all('input', {'name': True})} print(d)
prints:
{'sfqwWJOJi/E8DFDHSHB==': 'kgDcZHY+n', 'qw1NWJOJi/E8IyqHSHA==': 'gDcZHY+nV', 'Jsfqw1NdddfDDSDKKSL==': 'rNg4pUhnV'}
Based on @alecxe, this avoids KeyErrors and parses the form in a dictionary more ready for inquiries .
url = 'http://example.com/' + html_proc.form['action'] requests.post(url , data=d)
Although, if it gets more complicated (cookies, scripts), you can Mechanize .
The reason for TypeError is the confusion over the first parameter so that find () is "name". Instead of html_proc.find("input", attrs={'name': True}) . Also, for the attrs parameter, instead of typing {'value'}, use the dictionary {'value': True} .
source share