<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>Mithro rants about stuff &#187; cookie jar</title>
	<atom:link href="http://blog.mithis.net/archives/tag/cookie-jar/feed" rel="self" type="application/rss+xml" />
	<link>http://blog.mithis.net</link>
	<description></description>
	<lastBuildDate>Fri, 16 Dec 2011 06:02:58 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.2.1</generator>
		<item>
		<title>Reading Firefox 3.x cookies in Python</title>
		<link>http://blog.mithis.net/archives/python/90-firefox3-cookies-in-python</link>
		<comments>http://blog.mithis.net/archives/python/90-firefox3-cookies-in-python#comments</comments>
		<pubDate>Mon, 19 Jan 2009 03:28:28 +0000</pubDate>
		<dc:creator>mithro</dc:creator>
				<category><![CDATA[Python]]></category>
		<category><![CDATA[cookie jar]]></category>
		<category><![CDATA[cookies]]></category>
		<category><![CDATA[curl]]></category>
		<category><![CDATA[firefox]]></category>
		<category><![CDATA[sqlite]]></category>

		<guid isPermaLink="false">http://blog.mithis.net/?p=90</guid>
		<description><![CDATA[I found the following code snippet on my hard drive today. It allows you to access Firefox 3.x cookies in Python. Firefox 3.x moved away from the older text file format to a sqlite database. This code is useful if you want to access something behind an authentication gateway and you also access the page [...]]]></description>
			<content:encoded><![CDATA[<p>I found the following code snippet on my hard drive today. It allows you to access <a href="http://www.getfirefox.com" target="_self">Firefox 3.x</a> cookies in Python. Firefox 3.x moved away from the older text file format to a <a href="http://www.sqlite.org/">sqlite</a> database.</p>
<p>This code is useful if you want to access something behind an authentication gateway and you also access the page through your web browser. You can also use this code to convert a sqlite database into a cookie file <a href="http://curl.haxx.se/">CURL</a> can read.</p>
<p>I didn&#8217;t write this code, it was written by Noah Fontes when we where doing some scraping of the <a href="http://code.google.com/soc">Google Summer of Code</a> website (before I joined Google).</p>
<blockquote>

<div class="wp_syntax"><div class="code"><pre class="python" style="font-family:monospace;"><span style="color: #808080; font-style: italic;">#! /usr/bin/env python</span>
<span style="color: #808080; font-style: italic;"># Protocol implementation for handling gsocmentors.com transactions</span>
<span style="color: #808080; font-style: italic;"># Author: Noah Fontes nfontes AT cynigram DOT com</span>
<span style="color: #808080; font-style: italic;"># License: MIT</span>
&nbsp;
<span style="color: #ff7700;font-weight:bold;">def</span> sqlite2cookie<span style="color: black;">&#40;</span>filename<span style="color: black;">&#41;</span>:
    <span style="color: #ff7700;font-weight:bold;">from</span> <span style="color: #dc143c;">cStringIO</span> <span style="color: #ff7700;font-weight:bold;">import</span> <span style="color: #dc143c;">StringIO</span>
    <span style="color: #ff7700;font-weight:bold;">from</span> pysqlite2 <span style="color: #ff7700;font-weight:bold;">import</span> dbapi2 <span style="color: #ff7700;font-weight:bold;">as</span> sqlite
&nbsp;
    con = sqlite.<span style="color: black;">connect</span><span style="color: black;">&#40;</span>filename<span style="color: black;">&#41;</span>
&nbsp;
    cur = con.<span style="color: black;">cursor</span><span style="color: black;">&#40;</span><span style="color: black;">&#41;</span>
    cur.<span style="color: black;">execute</span><span style="color: black;">&#40;</span><span style="color: #483d8b;">&quot;select host, path, isSecure, expiry, name, value from moz_cookies&quot;</span><span style="color: black;">&#41;</span>
&nbsp;
    ftstr = <span style="color: black;">&#91;</span><span style="color: #483d8b;">&quot;FALSE&quot;</span>,<span style="color: #483d8b;">&quot;TRUE&quot;</span><span style="color: black;">&#93;</span>
&nbsp;
    s = <span style="color: #dc143c;">StringIO</span><span style="color: black;">&#40;</span><span style="color: black;">&#41;</span>
    s.<span style="color: black;">write</span><span style="color: black;">&#40;</span><span style="color: #483d8b;">&quot;&quot;&quot;<span style="color: #000099; font-weight: bold;">\</span>
# Netscape HTTP Cookie File
# http://www.netscape.com/newsref/std/cookie_spec.html
# This is a generated file!  Do not edit.
&quot;&quot;&quot;</span><span style="color: black;">&#41;</span>
    <span style="color: #ff7700;font-weight:bold;">for</span> item <span style="color: #ff7700;font-weight:bold;">in</span> cur.<span style="color: black;">fetchall</span><span style="color: black;">&#40;</span><span style="color: black;">&#41;</span>:
        s.<span style="color: black;">write</span><span style="color: black;">&#40;</span><span style="color: #483d8b;">&quot;%s<span style="color: #000099; font-weight: bold;">\t</span>%s<span style="color: #000099; font-weight: bold;">\t</span>%s<span style="color: #000099; font-weight: bold;">\t</span>%s<span style="color: #000099; font-weight: bold;">\t</span>%s<span style="color: #000099; font-weight: bold;">\t</span>%s<span style="color: #000099; font-weight: bold;">\t</span>%s<span style="color: #000099; font-weight: bold;">\n</span>&quot;</span> <span style="color: #66cc66;">%</span> <span style="color: black;">&#40;</span>
            item<span style="color: black;">&#91;</span><span style="color: #ff4500;">0</span><span style="color: black;">&#93;</span>, ftstr<span style="color: black;">&#91;</span>item<span style="color: black;">&#91;</span><span style="color: #ff4500;">0</span><span style="color: black;">&#93;</span>.<span style="color: black;">startswith</span><span style="color: black;">&#40;</span><span style="color: #483d8b;">'.'</span><span style="color: black;">&#41;</span><span style="color: black;">&#93;</span>, item<span style="color: black;">&#91;</span><span style="color: #ff4500;">1</span><span style="color: black;">&#93;</span>,
            ftstr<span style="color: black;">&#91;</span>item<span style="color: black;">&#91;</span><span style="color: #ff4500;">2</span><span style="color: black;">&#93;</span><span style="color: black;">&#93;</span>, item<span style="color: black;">&#91;</span><span style="color: #ff4500;">3</span><span style="color: black;">&#93;</span>, item<span style="color: black;">&#91;</span><span style="color: #ff4500;">4</span><span style="color: black;">&#93;</span>, item<span style="color: black;">&#91;</span><span style="color: #ff4500;">5</span><span style="color: black;">&#93;</span><span style="color: black;">&#41;</span><span style="color: black;">&#41;</span>
&nbsp;
    s.<span style="color: black;">seek</span><span style="color: black;">&#40;</span><span style="color: #ff4500;">0</span><span style="color: black;">&#41;</span>
&nbsp;
    cookie_jar = <span style="color: #dc143c;">cookielib</span>.<span style="color: black;">MozillaCookieJar</span><span style="color: black;">&#40;</span><span style="color: black;">&#41;</span>
    cookie_jar._really_load<span style="color: black;">&#40;</span>s, <span style="color: #483d8b;">''</span>, <span style="color: #008000;">True</span>, <span style="color: #008000;">True</span><span style="color: black;">&#41;</span>
    <span style="color: #ff7700;font-weight:bold;">return</span> cookie_jar</pre></div></div>

</blockquote>
]]></content:encoded>
			<wfw:commentRss>http://blog.mithis.net/archives/python/90-firefox3-cookies-in-python/feed</wfw:commentRss>
		<slash:comments>5</slash:comments>
		</item>
	</channel>
</rss>

