$ account MechanicalSoup
MechanicalSoup is a Python library that automates website interaction without executing JavaScript. It wraps requests.Session for HTTP transport and BeautifulSoup for HTML parsing, providing a mechanize-like API with two primary classes: Browser (stateless, low-level) and StatefulBrowser (maintains page, URL, and selected form state). The code base is compact (four core modules) and behavior is deliberately browser-faithful: disabled form controls (including those inside disabled fieldsets) are not submitted, the first option of a select without a selection is sent, enctype handling matches real browsers, and the Referer header is managed per HTML semantics. A notable security fix remediated CVE-2023-34457 by requiring explicit file-object opening instead of accepting path strings for multipart uploads. The test suite is extensive, runs at 100% coverage, and includes edge cases for encoding detection, duplicate submit buttons, form-associated external elements, and header overriding.