Name | browserfetch JSON |
Version |
0.8.1
JSON |
| download |
home_page | None |
Summary | fetch in Python using your browser! |
upload_time | 2024-07-28 16:02:00 |
maintainer | None |
docs_url | None |
author | None |
requires_python | >=3.11 |
license | None |
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/db/c7/d3a9b538e92dc7d37df26b5629fe6775b13a5569d9904526f9de910a4616/browserfetch-0.8.1.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.8.1",
"project_urls": {
"Homepage": "https://github.com/5j9/browserfetch"
},
"split_keywords": [
"browser",
" fetch",
" python",
" cookies"
],
"urls": [
{
"comment_text": "",
"digests": {
"blake2b_256": "5ef9df0e9105552985fb874419d7c5caaa2a546999e2d57d65f9fe220b4b6681",
"md5": "da32ffc9db6c6c7a52d8ac10fb2dc3fc",
"sha256": "7bbba2c439a118818524aaff48d7707df071735de8f510988f821a211aecb2a5"
},
"downloads": -1,
"filename": "browserfetch-0.8.1-py3-none-any.whl",
"has_sig": false,
"md5_digest": "da32ffc9db6c6c7a52d8ac10fb2dc3fc",
"packagetype": "bdist_wheel",
"python_version": "py3",
"requires_python": ">=3.11",
"size": 19303,
"upload_time": "2024-07-28T16:01:57",
"upload_time_iso_8601": "2024-07-28T16:01:57.256648Z",
"url": "https://files.pythonhosted.org/packages/5e/f9/df0e9105552985fb874419d7c5caaa2a546999e2d57d65f9fe220b4b6681/browserfetch-0.8.1-py3-none-any.whl",
"yanked": false,
"yanked_reason": null
},
{
"comment_text": "",
"digests": {
"blake2b_256": "dbc7d3a9b538e92dc7d37df26b5629fe6775b13a5569d9904526f9de910a4616",
"md5": "f4656028d3a6039cfb9ea9a1b5d27a9d",
"sha256": "c9f876b5f98caef197f4b99b38eaee878f0a0a9f03aa0258a2e3b62366353785"
},
"downloads": -1,
"filename": "browserfetch-0.8.1.tar.gz",
"has_sig": false,
"md5_digest": "f4656028d3a6039cfb9ea9a1b5d27a9d",
"packagetype": "sdist",
"python_version": "source",
"requires_python": ">=3.11",
"size": 18532,
"upload_time": "2024-07-28T16:02:00",
"upload_time_iso_8601": "2024-07-28T16:02:00.996023Z",
"url": "https://files.pythonhosted.org/packages/db/c7/d3a9b538e92dc7d37df26b5629fe6775b13a5569d9904526f9de910a4616/browserfetch-0.8.1.tar.gz",
"yanked": false,
"yanked_reason": null
}
],
"upload_time": "2024-07-28 16:02:00",
"github": true,
"gitlab": false,
"bitbucket": false,
"codeberg": false,
"github_user": "5j9",
"github_project": "browserfetch",
"travis_ci": false,
"coveralls": false,
"github_actions": false,
"lcname": "browserfetch"
}