Python library for automating website interaction — form submission, cookie handling, link following. Built on requests + BeautifulSoup. Current version is 1.4.0 (2023). Install name is MechanicalSoup (capital M and S), import is mechanicalsoup (all lowercase). Does NOT execute JavaScript — use Playwright or Selenium for JS-rendered pages. Maintenance status: low activity since 2023.
pip install MechanicalSoupVerified import paths — ran on the pinned version, not inferred.
StatefulBrowser for form-based workflows. Requires lxml or html.parser.
For JavaScript-rendered pages use Playwright (pip install playwright + playwright install) or Selenium instead.
pip install MechanicalSoup then import mechanicalsoup
Always pass raise_on_404=True: StatefulBrowser(raise_on_404=True). This raises LinkNotFoundError on 404 responses.
Use StatefulBrowser for multi-page workflows (login flows, form sequences). Use Browser only for simple one-shot requests.
Always pass a CSS selector: browser.select_form('#login-form'). Or use the nr= argument to select by index: browser.select_form('form', nr=1).