MechanicalSoup automates HTTP-level website interaction in Python. It handles cookies, redirects, link following, and form submission without running JavaScript.
Overview
MechanicalSoup is a Python library for automating interaction with websites at the HTTP and HTML level. It suits scripts that need to log in, submit search forms, follow links, and read result pages without a full browser engine.
The library keeps and sends cookies, follows redirects, navigates documents, and submits forms. It is built on Requests for HTTP sessions and BeautifulSoup for parsing and DOM navigation. It does not execute JavaScript, so it fits static or mostly server-rendered sites.
It was created as a maintained alternative to Mechanize for Python 3, offering a comparable workflow while relying on widely used Python HTTP and parsing stacks. Install it from PyPI or from source with pip, and use the StatefulBrowser or Browser APIs described in the project documentation.
Typical examples include filling search forms and collecting links from result pages, or walking multi-step login flows. The docs cover form edge cases, browser choice, and debugging.
Key features
- Automatic cookie storage and submission
- Redirect following
- Link navigation in parsed pages
- HTML form selection and submission
- StatefulBrowser and Browser APIs
- Built on Requests and BeautifulSoup
- PyPI distribution
- No JavaScript execution
Use cases
- Automating search form submissions
- Scripted login and session workflows
- Collecting links from result pages
- Simple scraping without a browser