Skip to main content
MechanicalSoup. A Python library for automating website interaction.

Home page

https://mechanicalsoup.readthedocs.io/

Overview

A Python library for automating interaction with websites. MechanicalSoup automatically stores and sends cookies, follows redirects, and can follow links and submit forms. It doesn’t do JavaScript.

MechanicalSoup was created by M Hickford, who was a fond user of the Mechanize library. Unfortunately, Mechanize was incompatible with Python 3 until 2019 and its development stalled for several years. MechanicalSoup provides a similar API, built on Python giants Requests (for HTTP sessions) and BeautifulSoup (for document navigation). Since 2017 it is a project actively maintained by a small team including @hemberger and @moy.

Gitter Chat

Installation

Latest Version Supported Versions

PyPy and PyPy3 are also supported (and tested against).

Download and install the latest released version from PyPI:

pip install MechanicalSoup

Download and install the development version from GitHub:

pip install git+https://github.com/MechanicalSoup/MechanicalSoup

Installing from source (installs the version in the current working directory):

python setup.py install

(In all cases, add --user to the install command to install in the current user’s home directory.)

Documentation

The full documentation is available on https://mechanicalsoup.readthedocs.io/. You may want to jump directly to the automatically generated API documentation.

Example

From examples/expl_duck_duck_go.py, code to get the results from a DuckDuckGo search:

"""Example usage of MechanicalSoup to get the results from
DuckDuckGo."""

import mechanicalsoup

# Connect to duckduckgo
browser = mechanicalsoup.StatefulBrowser()
browser.open("https://duckduckgo.com/")

# Fill-in the search form
browser.select_form('#search_form_homepage')
browser["q"] = "MechanicalSoup"
browser.submit_selected()

# Display the results
for link in browser.get_current_page().select('a.result__a'):
    print(link.text, '->', link.attrs['href'])

More examples are available in examples/.

For an example with a more complex form (checkboxes, radio buttons and textareas), read tests/test_browser.py and tests/test_form.py.

Development

Build Status Coverage Status Requirements Status Documentation Status CII Best Practices LGTM Alerts LGTM Grade

Instructions for building, testing and contributing to MechanicalSoup: see CONTRIBUTING.rst.

Common problems

Read the FAQ.

Release files for MechanicalSoup 0.12.0

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for MechanicalSoup 0.12.0
File Size Uploaded
MechanicalSoup-0.12.0.tar.gz 44.5 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for MechanicalSoup 0.12.0
File Interpreter ABI Platform
MechanicalSoup-0.12.0-py2.py3-none-any.whl Python 2, Python 3 none any Details

Total release size: 62.8 kB

Release files / MechanicalSoup-0.12.0.tar.gz

Download URL MechanicalSoup-0.12.0.tar.gz
Size 44.5 kB
Tags Source
SHA-256 checksum
How to use checksums
39a60627a97981869251837b8bd082485f2f681df8a3315836ffaa74663627bd
BLAKE2b-256 checksum
How to use checksums
c3f768b90159109031391aa0872f611aebeca425aa432d26a74ea28aad43e969
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/1.13.0 pkginfo/1.5.0.1 requests/2.20.1 setuptools/41.2.0 requests-toolbelt/0.9.1 tqdm/4.35.0 CPython/3.7.3

Release files / MechanicalSoup-0.12.0-py2.py3-none-any.whl

Download URL MechanicalSoup-0.12.0-py2.py3-none-any.whl
Size 18.3 kB
Tags Python 2 Python 3
SHA-256 checksum
How to use checksums
cddd80b0975f4fdafd137a473df4697854e6be3e332a5fa3200e607ee20d5238
BLAKE2b-256 checksum
How to use checksums
0bfe4f871ec3379080c5979815bfec3266871e555eebf4879f551a7e5dee4766
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/1.13.0 pkginfo/1.5.0.1 requests/2.20.1 setuptools/41.2.0 requests-toolbelt/0.9.1 tqdm/4.35.0 CPython/3.7.3
Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page