Skip to content

Instantly share code, notes, and snippets.

View CoMPaTech's full-sized avatar
😎
Coding along

Tom CoMPaTech

😎
Coding along
  • CoMPa Technology
  • The Netherlands
  • 04:26 (UTC -12:00)
View GitHub Profile
@CoMPaTech
CoMPaTech / gist:f42a306dda106809f20d1cc6f8c16584
Created March 20, 2018 21:18 — forked from simonw/gist:104413
Turn a BeautifulSoup form in to a dict of fields and default values - useful for screen scraping forms and then resubmitting them
def extract_form_fields(self, soup):
"Turn a BeautifulSoup form in to a dict of fields and default values"
fields = {}
for input in soup.findAll('input'):
# ignore submit/image with no name attribute
if input['type'] in ('submit', 'image') and not input.has_key('name'):
continue
# single element nome/value fields
if input['type'] in ('text', 'hidden', 'password', 'submit', 'image'):