# MechanicalSoup: A Python Library for Automating Website Interaction

This repository profile is provided by osrepos.com, an open source repository discovery platform.

Source: osrepos.com
Repository profile: https://osrepos.com/repo/mechanicalsoup-mechanicalsoup
Generated for open source discovery and AI-assisted research.

MechanicalSoup is a powerful Python library designed for automating interactions with websites. Built upon Requests and BeautifulSoup, it simplifies tasks like storing cookies, following redirects, and submitting forms. It's an excellent tool for web automation tasks that don't require JavaScript execution.

GitHub: https://github.com/MechanicalSoup/MechanicalSoup
OSRepos URL: https://osrepos.com/repo/mechanicalsoup-mechanicalsoup

## Summary

MechanicalSoup is a powerful Python library designed for automating interactions with websites. Built upon Requests and BeautifulSoup, it simplifies tasks like storing cookies, following redirects, and submitting forms. It's an excellent tool for web automation tasks that don't require JavaScript execution.

## Topics

- mechanicalsoup
- python
- web automation
- web scraping
- beautifulsoup
- requests
- pypi
- python-library

## Repository Information

Last analyzed by OSRepos: Fri Jul 24 2026 12:35:08 GMT+0100 (Western European Summer Time)
Detail views: 3
GitHub clicks: 1

## Safety Notice

OSRepos shares public repositories for knowledge and discovery only. Review source code, dependencies, licenses, and security implications before running or installing anything.

## Content

## Introduction
MechanicalSoup is a Python library for automating interaction with websites. It provides a convenient way to navigate web pages, fill out forms, and follow links programmatically. Inspired by the Mechanize library, MechanicalSoup is built on top of robust Python giants: Requests for handling HTTP sessions and BeautifulSoup for parsing and navigating HTML documents. It automatically manages cookies, follows redirects, and handles form submissions, making web automation straightforward for non-JavaScript-heavy sites. Maintained by a dedicated team since 2017, it offers a reliable solution for many web scraping and interaction needs.

## Installation
To get started with MechanicalSoup, you can easily install it using pip. The library supports Python 3 and PyPy3.


pip install MechanicalSoup


For the latest development version, you can install directly from GitHub:


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


## Examples
MechanicalSoup simplifies common web interaction tasks. Here's an example demonstrating how to use it to perform a search on Qwant and extract the results:

python
import re
import mechanicalsoup
import html
import urllib.parse

# Connect to Qwant
browser = mechanicalsoup.StatefulBrowser(user_agent='MechanicalSoup')
browser.open("https://lite.qwant.com/")

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

# Display the results
for link in browser.page.select('.result a'):
    # Qwant shows redirection links, not the actual URL, so extract
    # the actual URL from the redirect link:
    href = link.attrs['href']
    m = re.match(r"^/redirect/[^/]*/(.*)$", href)
    if m:
        href = urllib.parse.unquote(m.group(1))
    print(link.text, '->', href)


This example showcases how to open a URL, select a form, fill in input fields, submit the form, and then parse the results using BeautifulSoup's powerful selectors.

## Why Use MechanicalSoup?
MechanicalSoup excels in scenarios where you need to automate interactions with websites that don't heavily rely on client-side JavaScript. Its key advantages include:

*   **Simplicity**: Provides a high-level API for common web tasks.
*   **Robustness**: Built on top of `Requests` for reliable HTTP handling and `BeautifulSoup` for efficient HTML parsing.
*   **Stateful Browsing**: Automatically handles cookies and follows redirects, mimicking a real browser's behavior without the overhead of a full browser engine.
*   **Form Submission**: Easily select and submit forms, including handling various input types.
*   **Pythonic**: Integrates seamlessly into Python projects, making web automation accessible to Python developers.

## Links
For more detailed information, documentation, and to contribute, please refer to the official resources:

*   [Official Documentation](https://mechanicalsoup.readthedocs.io/) (opens in a new tab)
*   [GitHub Repository](https://github.com/MechanicalSoup/MechanicalSoup) (opens in a new tab)
*   [PyPI Page](https://pypi.python.org/pypi/MechanicalSoup/) (opens in a new tab)