Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse code

firefox/export_firefox_cookies.py added

  • Loading branch information...
commit 85a64671323db14fa43b2f9207ecf22a97439284 1 parent 52866aa
Jabba Laci authored

Showing 2 changed files with 69 additions and 0 deletions. Show diff stats Hide diff stats

  1. +7 0 README
  2. +62 0 firefox/export_firefox_cookies.py
7 README
@@ -6,6 +6,13 @@ Here I collect some small command-line utils.
6 6 Author: Laszlo Szathmary, 2011 (jabba.laci@gmail.com)
7 7 Github: https://github.com/jabbalaci/Bash-Utils
8 8
  9 +firefox/export_firefox_cookies.py
  10 + Website: https://ubuntuincident.wordpress.com/2011/09/05/download-pages-with-wget-that-are-protected-by-cookies/
  11 + Original script written by Dirk Sohler (https://old.0x7be.de/2008/06/19/firefox-3-und-cookiestxt/).
  12 + This script extracts cookies from Firefox's cookies.sqlite file hat are
  13 + specific to a given host. The exported cookies are saved in the file cookies.txt.
  14 + Usage: ./export_firefox_cookies.py <host>
  15 +
9 16 reddit/reddit_get_all_pages.py
10 17 Website: https://ubuntuincident.wordpress.com/2011/08/27/browse-all-pages-of-a-subreddit/
11 18 This script allows you to browse all the older pages of a subreddit.
62 firefox/export_firefox_cookies.py
... ... @@ -0,0 +1,62 @@
  1 +#!/usr/bin/env python
  2 +
  3 +"""
  4 +Extract Firefox cookies
  5 +=======================
  6 +
  7 +This script extracts cookies from Firefox's cookies.sqlite file
  8 +that are specific to a given host. The exported cookies are saved
  9 +in the file cookies.txt.
  10 +
  11 +Then, you can use this exported file with wget to download content
  12 +that require authentication via cookies:
  13 +
  14 +wget --cookies=on --load-cookies=cookies.txt --keep-session-cookies "http://..."
  15 +
  16 +The original script was written by Dirk Sohler:
  17 +https://old.0x7be.de/2008/06/19/firefox-3-und-cookiestxt/
  18 +
  19 +This version is a bit refactored but does exactly the same.
  20 +Website: https://ubuntuincident.wordpress.com/2011/09/05/download-pages-with-wget-that-are-protected-by-cookies/
  21 +GitHub: https://github.com/jabbalaci/Bash-Utils (see the firefox/ folder)
  22 +"""
  23 +
  24 +import os
  25 +import sys
  26 +import sqlite3 as db
  27 +
  28 +USERDIR = 'w3z7c6j4.default'
  29 +
  30 +COOKIEDB = os.path.expanduser('~') + '/.mozilla/firefox/' + USERDIR + '/cookies.sqlite'
  31 +OUTPUT = 'cookies.txt'
  32 +CONTENTS = "host, path, isSecure, expiry, name, value"
  33 +
  34 +
  35 +def extract(host):
  36 + conn = db.connect(COOKIEDB)
  37 + cursor = conn.cursor()
  38 +
  39 + sql = "SELECT {c} FROM moz_cookies WHERE host LIKE '%{h}%'".format(c=CONTENTS, h=host)
  40 + cursor.execute(sql)
  41 +
  42 + out = open(OUTPUT, 'w')
  43 + cnt = 0
  44 + for row in cursor.fetchall():
  45 + s = "{0}\tTRUE\t{1}\t{2}\t{3}\t{4}\t{5}\n".format(row[0], row[1],
  46 + str(bool(row[2])).upper(), row[3], str(row[4]), str(row[5]))
  47 + out.write(s)
  48 + cnt += 1
  49 +
  50 + print "Gesucht nach: {0}".format(host)
  51 + print "Exportiert: {0}".format(cnt)
  52 +
  53 + out.close()
  54 + conn.close()
  55 +
  56 +
  57 +if __name__ == "__main__":
  58 + if len(sys.argv) == 1:
  59 + print "{0}: error: specify the host.".format(sys.argv[0])
  60 + sys.exit()
  61 + else:
  62 + extract(sys.argv[1])

0 comments on commit 85a6467

Please sign in to comment.
Something went wrong with that request. Please try again.