MechanicalSoup

1.4.0 · active · verified Fri Mar 27

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.

Warnings

Install

Imports

Quickstart

StatefulBrowser for form-based workflows. Requires lxml or html.parser.

import mechanicalsoup

# StatefulBrowser is the high-level interface
browser = mechanicalsoup.StatefulBrowser(
    soup_config={'features': 'lxml'},
    raise_on_404=True
)

# Navigate to a page
browser.open('https://httpbin.org/forms/post')

# Select and fill a form
browser.select_form('form')  # or CSS selector like '#login-form'
browser['custname'] = 'Alice'
browser['custtel'] = '555-1234'
browser['comments'] = 'Hello!'

# Submit the form
response = browser.submit_selected()
print(response.status_code)

# Access the resulting page
print(browser.page.title.string)

view raw JSON →