browserfetch


Namebrowserfetch JSON
Version 0.10.0 PyPI version JSON
download
home_pageNone
Summaryfetch in Python using your browser!
upload_time2025-01-17 08:39:30
maintainerNone
docs_urlNone
authorNone
requires_python>=3.11
licenseNone
keywords browser fetch python cookies
VCS
bugtrack_url
requirements No requirements were recorded.
Travis-CI No Travis.
coveralls test coverage No coveralls.
            Fetch using your browser.

Let the browser manage cookies for you.

⚠️ Incomplete. Not tested thoroughly. Consider using `Playwright`_, especially for more complex scenarios.

Usage
-----
1. You'll run a Python script containing some code like this:

.. code-block:: python

    from asyncio import gather, new_event_loop

    from browserfetch import fetch, get, post, run_server


    async def main():
        response1, response2, reponse3 = await gather(
            get('https://example.com/path1', params={'a': 1}),
            fetch('https://example.com/image.png'),
            post('https://example.com/path2', data={'a': 1}),
        )
        # do stuff with retrieved responses


    loop = new_event_loop()
    loop.create_task(start_server())
    loop.run_until_complete(main())


2. Open your browser, goto http://example.com (perhaps solve a captcha and log in).
3. Copy the contents of `browserfetch.js`_ file and paste it in browser's console. (You can use a browser extensions like violentmonkey_/tampermonkey_ to do this step for you.)

That's it! Your Python script starts handling requests.
The browser tab should remain open of-coarse.

The server can handle multiple websocket connections from different websites simultaneously.

How it works
------------
``browserfetch`` communicates with your browser using a websocket. The ``fetch`` function just passes the request to browser and it is the browser that handles the actual request. Response data is sent back to Python using the same WebSocket connection.

Motivations
-----------
* `browser_cookie3 stopped working on Chrome-based browsers`_. There is a workaround: ShadowCopy, but it requires admin privilege.
* Another issue with browser_cookie's approach is that it retrieves cookies from cookie files, but these files are not updated instantly. Thus, you might have to wait or retry a few times before you can successfully access newly set cookies.
* ShadowCopying and File access are slow and inefficient operations.

Downsides
---------
* Setting up ``browserfetch`` is more cumbersome since it requires running a Python server and also injecting a small script into the webpage. Using ``browser_cookie3`` might be a better choice if there are many websites that you need to communicate with.

.. _playwright: https://playwright.dev/python/docs/intro
.. _`browser_cookie3 stopped working on Chrome-based browsers`: https://github.com/borisbabic/browser_cookie3/issues/180
.. _tampermonkey: https://github.com/Tampermonkey/tampermonkey
.. _violentmonkey: https://github.com/violentmonkey/violentmonkey
.. _browserfetch.js: https://github.com/5j9/browserfetch/blob/master/browserfetch/browserfetch.js


            

Raw data

            {
    "_id": null,
    "home_page": null,
    "name": "browserfetch",
    "maintainer": null,
    "docs_url": null,
    "requires_python": ">=3.11",
    "maintainer_email": null,
    "keywords": "browser, fetch, python, cookies",
    "author": null,
    "author_email": null,
    "download_url": "https://files.pythonhosted.org/packages/91/75/bfdca37293ff2a5590475a881cc1cc861031400a3221e107ff9260570709/browserfetch-0.10.0.tar.gz",
    "platform": null,
    "description": "Fetch using your browser.\n\nLet the browser manage cookies for you.\n\n\u26a0\ufe0f Incomplete. Not tested thoroughly. Consider using `Playwright`_, especially for more complex scenarios.\n\nUsage\n-----\n1. You'll run a Python script containing some code like this:\n\n.. code-block:: python\n\n    from asyncio import gather, new_event_loop\n\n    from browserfetch import fetch, get, post, run_server\n\n\n    async def main():\n        response1, response2, reponse3 = await gather(\n            get('https://example.com/path1', params={'a': 1}),\n            fetch('https://example.com/image.png'),\n            post('https://example.com/path2', data={'a': 1}),\n        )\n        # do stuff with retrieved responses\n\n\n    loop = new_event_loop()\n    loop.create_task(start_server())\n    loop.run_until_complete(main())\n\n\n2. Open your browser, goto http://example.com (perhaps solve a captcha and log in).\n3. Copy the contents of `browserfetch.js`_ file and paste it in browser's console. (You can use a browser extensions like violentmonkey_/tampermonkey_ to do this step for you.)\n\nThat's it! Your Python script starts handling requests.\nThe browser tab should remain open of-coarse.\n\nThe server can handle multiple websocket connections from different websites simultaneously.\n\nHow it works\n------------\n``browserfetch`` communicates with your browser using a websocket. The ``fetch`` function just passes the request to browser and it is the browser that handles the actual request. Response data is sent back to Python using the same WebSocket connection.\n\nMotivations\n-----------\n* `browser_cookie3 stopped working on Chrome-based browsers`_. There is a workaround: ShadowCopy, but it requires admin privilege.\n* Another issue with browser_cookie's approach is that it retrieves cookies from cookie files, but these files are not updated instantly. Thus, you might have to wait or retry a few times before you can successfully access newly set cookies.\n* ShadowCopying and File access are slow and inefficient operations.\n\nDownsides\n---------\n* Setting up ``browserfetch`` is more cumbersome since it requires running a Python server and also injecting a small script into the webpage. Using ``browser_cookie3`` might be a better choice if there are many websites that you need to communicate with.\n\n.. _playwright: https://playwright.dev/python/docs/intro\n.. _`browser_cookie3 stopped working on Chrome-based browsers`: https://github.com/borisbabic/browser_cookie3/issues/180\n.. _tampermonkey: https://github.com/Tampermonkey/tampermonkey\n.. _violentmonkey: https://github.com/violentmonkey/violentmonkey\n.. _browserfetch.js: https://github.com/5j9/browserfetch/blob/master/browserfetch/browserfetch.js\n\n",
    "bugtrack_url": null,
    "license": null,
    "summary": "fetch in Python using your browser!",
    "version": "0.10.0",
    "project_urls": {
        "Homepage": "https://github.com/5j9/browserfetch"
    },
    "split_keywords": [
        "browser",
        " fetch",
        " python",
        " cookies"
    ],
    "urls": [
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "e8a33fbca76a2d8ac253206457aca491b2bd9d22ceee546073ec7485a14c00be",
                "md5": "6a68bc0cd8518245e3896bf1311c07d4",
                "sha256": "dd0fc769a58a0283d4a79ff5e2f169396121b6877d2d4f7bcc8032ee6608c014"
            },
            "downloads": -1,
            "filename": "browserfetch-0.10.0-py3-none-any.whl",
            "has_sig": false,
            "md5_digest": "6a68bc0cd8518245e3896bf1311c07d4",
            "packagetype": "bdist_wheel",
            "python_version": "py3",
            "requires_python": ">=3.11",
            "size": 19986,
            "upload_time": "2025-01-17T08:38:24",
            "upload_time_iso_8601": "2025-01-17T08:38:24.473535Z",
            "url": "https://files.pythonhosted.org/packages/e8/a3/3fbca76a2d8ac253206457aca491b2bd9d22ceee546073ec7485a14c00be/browserfetch-0.10.0-py3-none-any.whl",
            "yanked": false,
            "yanked_reason": null
        },
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "9175bfdca37293ff2a5590475a881cc1cc861031400a3221e107ff9260570709",
                "md5": "8a62e0a93cd31690ddbf535eb20ed746",
                "sha256": "7d2825b39a54df86088837130a298adbedab581fc7f451da25af70eab39ef17b"
            },
            "downloads": -1,
            "filename": "browserfetch-0.10.0.tar.gz",
            "has_sig": false,
            "md5_digest": "8a62e0a93cd31690ddbf535eb20ed746",
            "packagetype": "sdist",
            "python_version": "source",
            "requires_python": ">=3.11",
            "size": 19179,
            "upload_time": "2025-01-17T08:39:30",
            "upload_time_iso_8601": "2025-01-17T08:39:30.313791Z",
            "url": "https://files.pythonhosted.org/packages/91/75/bfdca37293ff2a5590475a881cc1cc861031400a3221e107ff9260570709/browserfetch-0.10.0.tar.gz",
            "yanked": false,
            "yanked_reason": null
        }
    ],
    "upload_time": "2025-01-17 08:39:30",
    "github": true,
    "gitlab": false,
    "bitbucket": false,
    "codeberg": false,
    "github_user": "5j9",
    "github_project": "browserfetch",
    "travis_ci": false,
    "coveralls": false,
    "github_actions": false,
    "lcname": "browserfetch"
}
        
Elapsed time: 0.93314s