Name | browsercookie JSON |
Version |
0.7.9
JSON |
| download |
home_page | https://github.com/richardpenman/browsercookie |
Summary | Loads cookies from your browser into a cookiejar object so can download with urllib and other libraries the same content you see in the web browser. |
upload_time | 2024-05-17 02:38:01 |
maintainer | None |
docs_url | None |
author | Richard Penman |
requires_python | >=3.4 |
license | lgpl |
keywords |
|
VCS |
|
bugtrack_url |
|
requirements |
No requirements were recorded.
|
Travis-CI |
No Travis.
|
coveralls test coverage |
No coveralls.
|
Browser Cookie
==============
The **browsercookie** module loads cookies used by your web browser
into a cookiejar object. This can be useful if you want to use python to
download the same content you see in the web browser without needing to
login.
Install
-------
.. sourcecode:: bash
pip install browsercookie
On Windows the builtin sqlite module will raise an error when loading
the FireFox database. An updated version of sqlite can be installed with:
.. sourcecode:: bash
pip install pysqlite
Usage
-----
Here is a hack to extract the title from a webpage:
.. sourcecode:: python
>>> import re
>>> get_title = lambda html: re.findall('<title>(.*?)</title>', html, flags=re.DOTALL)[0].strip()
And here is the webpage title when downloaded normally:
.. sourcecode:: python
>>> import urllib2
>>> url = 'https://bitbucket.org/'
>>> public_html = urllib2.urlopen(url).read()
>>> get_title(public_html)
'Git and Mercurial code management for teams'
Now let's try with **browsercookie** - make sure you are logged into
Bitbucket in Firefox before trying this example:
.. sourcecode:: python
>>> import browsercookie
>>> cj = browsercookie.firefox()
>>> opener = urllib2.build_opener(urllib2.HTTPCookieProcessor(cj))
>>> login_html = opener.open(url).read()
>>> get_title(login_html)
'richardpenman / home — Bitbucket'
Differences with Python3:
.. sourcecode:: python
>>> import urllib.request
>>> public_html = urllib.request.urlopen(url).read()
>>> opener = urllib.request.build_opener(urllib.request.HTTPCookieProcessor(cj))
You should see your own username here, meaning the module successfully
loaded the cookies from Firefox.
Here is an alternative example with
`requests <http://docs.python-requests.org/en/latest/>`__, this time
loading the Chrome cookies. Again make sure you are logged into
Bitbucket in Chrome before running this:
.. sourcecode:: python
>>> import requests
>>> cj = browsercookie.chrome()
>>> r = requests.get(url, cookies=cj)
>>> get_title(r.content)
'richardpenman / home — Bitbucket'
Alternatively if you don't know/care which browser has the cookies you
want then all available browser cookies can be loaded:
.. sourcecode:: python
>>> cj = browsercookie.load()
>>> r = requests.get(url, cookies=cj)
>>> get_title(r.content)
'richardpenman / home — Bitbucket'
Contribute
----------
So far the following platforms are supported:
- **Chrome:** Linux, OSX, Windows
- **Firefox:** Linux, OSX, Windows
However I only tested on a single version of each browser and so am not
sure if the cookie sqlite format changes location or format in
earlier/later versions. If you experience a problem please `open an
issue <https://bitbucket.org/richardpenman/browsercookie/issues/new>`__
which includes details of the browser version and operating system. Also
patches to support other browsers are very welcome, particularly for
Internet Explorer on Windows.
Acknowledgements
----------------
* Nathan Henrie for his example of `how to decode the Chrome cookies <http://n8henrie.com/2013/11/use-chromes-cookies-for-easier-downloading-with-python-requests/>`__
* Graeme Robinson for his Chrome Windows patch
Raw data
{
"_id": null,
"home_page": "https://github.com/richardpenman/browsercookie",
"name": "browsercookie",
"maintainer": null,
"docs_url": null,
"requires_python": ">=3.4",
"maintainer_email": null,
"keywords": null,
"author": "Richard Penman",
"author_email": "richard.penman@gmail.com",
"download_url": "https://files.pythonhosted.org/packages/77/fb/246517bd29d5706f0243b5113aa7e987b2caa1b705c7e7ebf8fc975d2c9c/browsercookie-0.7.9.tar.gz",
"platform": null,
"description": "Browser Cookie\n==============\n\nThe **browsercookie** module loads cookies used by your web browser\ninto a cookiejar object. This can be useful if you want to use python to\ndownload the same content you see in the web browser without needing to\nlogin.\n\nInstall\n-------\n\n.. sourcecode:: bash\n\n pip install browsercookie\n\nOn Windows the builtin sqlite module will raise an error when loading\nthe FireFox database. An updated version of sqlite can be installed with:\n\n.. sourcecode:: bash\n\n pip install pysqlite\n\nUsage\n-----\n\nHere is a hack to extract the title from a webpage:\n\n.. sourcecode:: python\n\n >>> import re\n >>> get_title = lambda html: re.findall('<title>(.*?)</title>', html, flags=re.DOTALL)[0].strip()\n\nAnd here is the webpage title when downloaded normally:\n\n.. sourcecode:: python\n\n >>> import urllib2\n >>> url = 'https://bitbucket.org/'\n >>> public_html = urllib2.urlopen(url).read()\n >>> get_title(public_html)\n 'Git and Mercurial code management for teams'\n\nNow let's try with **browsercookie** - make sure you are logged into\nBitbucket in Firefox before trying this example:\n\n.. sourcecode:: python\n\n >>> import browsercookie\n >>> cj = browsercookie.firefox()\n >>> opener = urllib2.build_opener(urllib2.HTTPCookieProcessor(cj))\n >>> login_html = opener.open(url).read()\n >>> get_title(login_html)\n 'richardpenman / home — Bitbucket'\n\nDifferences with Python3:\n\n.. sourcecode:: python\n \n >>> import urllib.request\n >>> public_html = urllib.request.urlopen(url).read()\n >>> opener = urllib.request.build_opener(urllib.request.HTTPCookieProcessor(cj))\n\n\nYou should see your own username here, meaning the module successfully\nloaded the cookies from Firefox.\n\nHere is an alternative example with\n`requests <http://docs.python-requests.org/en/latest/>`__, this time\nloading the Chrome cookies. Again make sure you are logged into\nBitbucket in Chrome before running this:\n\n.. sourcecode:: python\n\n >>> import requests\n >>> cj = browsercookie.chrome()\n >>> r = requests.get(url, cookies=cj)\n >>> get_title(r.content)\n 'richardpenman / home — Bitbucket'\n\nAlternatively if you don't know/care which browser has the cookies you\nwant then all available browser cookies can be loaded:\n\n.. sourcecode:: python\n \n >>> cj = browsercookie.load()\n >>> r = requests.get(url, cookies=cj)\n >>> get_title(r.content)\n 'richardpenman / home — Bitbucket'\n\nContribute\n----------\n\nSo far the following platforms are supported:\n\n- **Chrome:** Linux, OSX, Windows\n- **Firefox:** Linux, OSX, Windows\n\nHowever I only tested on a single version of each browser and so am not\nsure if the cookie sqlite format changes location or format in\nearlier/later versions. If you experience a problem please `open an\nissue <https://bitbucket.org/richardpenman/browsercookie/issues/new>`__\nwhich includes details of the browser version and operating system. Also\npatches to support other browsers are very welcome, particularly for\nInternet Explorer on Windows.\n\nAcknowledgements\n----------------\n\n* Nathan Henrie for his example of `how to decode the Chrome cookies <http://n8henrie.com/2013/11/use-chromes-cookies-for-easier-downloading-with-python-requests/>`__\n* Graeme Robinson for his Chrome Windows patch\n",
"bugtrack_url": null,
"license": "lgpl",
"summary": "Loads cookies from your browser into a cookiejar object so can download with urllib and other libraries the same content you see in the web browser.",
"version": "0.7.9",
"project_urls": {
"Homepage": "https://github.com/richardpenman/browsercookie"
},
"split_keywords": [],
"urls": [
{
"comment_text": "",
"digests": {
"blake2b_256": "b1e7f9b621e3031d036fd8c8acdaf645ca031baffa7829f29b58d0c340111846",
"md5": "c46c5efb3655f13aa113a063c493359c",
"sha256": "2bb0d9e644740a156f2f61964c329d3a0c87cf394103df5ab150f8ce2f93977e"
},
"downloads": -1,
"filename": "browsercookie-0.7.9-py3-none-any.whl",
"has_sig": false,
"md5_digest": "c46c5efb3655f13aa113a063c493359c",
"packagetype": "bdist_wheel",
"python_version": "py3",
"requires_python": ">=3.4",
"size": 17539,
"upload_time": "2024-05-17T02:37:57",
"upload_time_iso_8601": "2024-05-17T02:37:57.723822Z",
"url": "https://files.pythonhosted.org/packages/b1/e7/f9b621e3031d036fd8c8acdaf645ca031baffa7829f29b58d0c340111846/browsercookie-0.7.9-py3-none-any.whl",
"yanked": false,
"yanked_reason": null
},
{
"comment_text": "",
"digests": {
"blake2b_256": "77fb246517bd29d5706f0243b5113aa7e987b2caa1b705c7e7ebf8fc975d2c9c",
"md5": "72e1ae2a319240573bbc4870c97b7f53",
"sha256": "6537515409affd84040d66b7744d9f96d3dd4a89320349df7764c5d7d123d446"
},
"downloads": -1,
"filename": "browsercookie-0.7.9.tar.gz",
"has_sig": false,
"md5_digest": "72e1ae2a319240573bbc4870c97b7f53",
"packagetype": "sdist",
"python_version": "source",
"requires_python": ">=3.4",
"size": 18517,
"upload_time": "2024-05-17T02:38:01",
"upload_time_iso_8601": "2024-05-17T02:38:01.154746Z",
"url": "https://files.pythonhosted.org/packages/77/fb/246517bd29d5706f0243b5113aa7e987b2caa1b705c7e7ebf8fc975d2c9c/browsercookie-0.7.9.tar.gz",
"yanked": false,
"yanked_reason": null
}
],
"upload_time": "2024-05-17 02:38:01",
"github": true,
"gitlab": false,
"bitbucket": false,
"codeberg": false,
"github_user": "richardpenman",
"github_project": "browsercookie",
"travis_ci": false,
"coveralls": false,
"github_actions": false,
"lcname": "browsercookie"
}