{"name":"MechanicalSoup: A Python Library for Automating Website Interaction","description":"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","url":"https://osrepos.com/repo/mechanicalsoup-mechanicalsoup","source":"osrepos.com","sourceDescription":"This repository profile is provided by osrepos.com, an open source repository discovery platform.","repositoryProfile":"https://osrepos.com/repo/mechanicalsoup-mechanicalsoup","generatedFor":"open source discovery and AI-assisted research","markdown":"https://osrepos.com/repo/mechanicalsoup-mechanicalsoup.md","json":"https://osrepos.com/repo/mechanicalsoup-mechanicalsoup.json","topics":["mechanicalsoup","python","web automation","web scraping","beautifulsoup","requests","pypi","python-library"],"keywords":["mechanicalsoup","python","web automation","web scraping","beautifulsoup","requests","pypi","python-library"],"stars":null,"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.","content":"## Introduction\nMechanicalSoup 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.\n\n## Installation\nTo get started with MechanicalSoup, you can easily install it using pip. The library supports Python 3 and PyPy3.\n\n\npip install MechanicalSoup\n\n\nFor the latest development version, you can install directly from GitHub:\n\n\npip install git+https://github.com/MechanicalSoup/MechanicalSoup\n\n\n## Examples\nMechanicalSoup simplifies common web interaction tasks. Here's an example demonstrating how to use it to perform a search on Qwant and extract the results:\n\npython\nimport re\nimport mechanicalsoup\nimport html\nimport urllib.parse\n\n# Connect to Qwant\nbrowser = mechanicalsoup.StatefulBrowser(user_agent='MechanicalSoup')\nbrowser.open(\"https://lite.qwant.com/\")\n\n# Fill-in the search form\nbrowser.select_form('#search-form')\nbrowser[\"q\"] = \"MechanicalSoup\"\nbrowser.submit_selected()\n\n# Display the results\nfor link in browser.page.select('.result a'):\n    # Qwant shows redirection links, not the actual URL, so extract\n    # the actual URL from the redirect link:\n    href = link.attrs['href']\n    m = re.match(r\"^/redirect/[^/]*/(.*)$\", href)\n    if m:\n        href = urllib.parse.unquote(m.group(1))\n    print(link.text, '->', href)\n\n\nThis 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.\n\n## Why Use MechanicalSoup?\nMechanicalSoup excels in scenarios where you need to automate interactions with websites that don't heavily rely on client-side JavaScript. Its key advantages include:\n\n*   **Simplicity**: Provides a high-level API for common web tasks.\n*   **Robustness**: Built on top of `Requests` for reliable HTTP handling and `BeautifulSoup` for efficient HTML parsing.\n*   **Stateful Browsing**: Automatically handles cookies and follows redirects, mimicking a real browser's behavior without the overhead of a full browser engine.\n*   **Form Submission**: Easily select and submit forms, including handling various input types.\n*   **Pythonic**: Integrates seamlessly into Python projects, making web automation accessible to Python developers.\n\n## Links\nFor more detailed information, documentation, and to contribute, please refer to the official resources:\n\n*   [Official Documentation](https://mechanicalsoup.readthedocs.io/) (opens in a new tab)\n*   [GitHub Repository](https://github.com/MechanicalSoup/MechanicalSoup) (opens in a new tab)\n*   [PyPI Page](https://pypi.python.org/pypi/MechanicalSoup/) (opens in a new tab)","metrics":{"detailViews":3,"githubClicks":1},"dates":{"published":null,"modified":"2026-07-24T11:35:08.000Z"}}