Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

firefox/export_firefox_cookies.py added

  • Loading branch information...
commit 85a64671323db14fa43b2f9207ecf22a97439284 1 parent 52866aa
Laszlo Szathmary authored
Showing with 69 additions and 0 deletions.
  1. +7 −0 README
  2. +62 −0 firefox/export_firefox_cookies.py
7 README
View
@@ -6,6 +6,13 @@ Here I collect some small command-line utils.
Author: Laszlo Szathmary, 2011 (jabba.laci@gmail.com)
Github: https://github.com/jabbalaci/Bash-Utils
+firefox/export_firefox_cookies.py
+ Website: https://ubuntuincident.wordpress.com/2011/09/05/download-pages-with-wget-that-are-protected-by-cookies/
+ Original script written by Dirk Sohler (https://old.0x7be.de/2008/06/19/firefox-3-und-cookiestxt/).
+ This script extracts cookies from Firefox's cookies.sqlite file hat are
+ specific to a given host. The exported cookies are saved in the file cookies.txt.
+ Usage: ./export_firefox_cookies.py <host>
+
reddit/reddit_get_all_pages.py
Website: https://ubuntuincident.wordpress.com/2011/08/27/browse-all-pages-of-a-subreddit/
This script allows you to browse all the older pages of a subreddit.
62 firefox/export_firefox_cookies.py
View
@@ -0,0 +1,62 @@
+#!/usr/bin/env python
+
+"""
+Extract Firefox cookies
+=======================
+
+This script extracts cookies from Firefox's cookies.sqlite file
+that are specific to a given host. The exported cookies are saved
+in the file cookies.txt.
+
+Then, you can use this exported file with wget to download content
+that require authentication via cookies:
+
+wget --cookies=on --load-cookies=cookies.txt --keep-session-cookies "http://..."
+
+The original script was written by Dirk Sohler:
+https://old.0x7be.de/2008/06/19/firefox-3-und-cookiestxt/
+
+This version is a bit refactored but does exactly the same.
+Website: https://ubuntuincident.wordpress.com/2011/09/05/download-pages-with-wget-that-are-protected-by-cookies/
+GitHub: https://github.com/jabbalaci/Bash-Utils (see the firefox/ folder)
+"""
+
+import os
+import sys
+import sqlite3 as db
+
+USERDIR = 'w3z7c6j4.default'
+
+COOKIEDB = os.path.expanduser('~') + '/.mozilla/firefox/' + USERDIR + '/cookies.sqlite'
+OUTPUT = 'cookies.txt'
+CONTENTS = "host, path, isSecure, expiry, name, value"
+
+
+def extract(host):
+ conn = db.connect(COOKIEDB)
+ cursor = conn.cursor()
+
+ sql = "SELECT {c} FROM moz_cookies WHERE host LIKE '%{h}%'".format(c=CONTENTS, h=host)
+ cursor.execute(sql)
+
+ out = open(OUTPUT, 'w')
+ cnt = 0
+ for row in cursor.fetchall():
+ s = "{0}\tTRUE\t{1}\t{2}\t{3}\t{4}\t{5}\n".format(row[0], row[1],
+ str(bool(row[2])).upper(), row[3], str(row[4]), str(row[5]))
+ out.write(s)
+ cnt += 1
+
+ print "Gesucht nach: {0}".format(host)
+ print "Exportiert: {0}".format(cnt)
+
+ out.close()
+ conn.close()
+
+
+if __name__ == "__main__":
+ if len(sys.argv) == 1:
+ print "{0}: error: specify the host.".format(sys.argv[0])
+ sys.exit()
+ else:
+ extract(sys.argv[1])
Please sign in to comment.
Something went wrong with that request. Please try again.