Skip to content

Instantly share code, notes, and snippets.

@kk6
Created October 23, 2011 17:29
Show Gist options
  • Save kk6/1307611 to your computer and use it in GitHub Desktop.
Save kk6/1307611 to your computer and use it in GitHub Desktop.
http://goo.gl/aw41c を見てなんとなく書いてみるなど。
#-*- coding:utf-8 -*-
# Python 3.2 でのみ動作確認済み
# Python 2.7 で実行するとDatabaseError になりました。
import sqlite3
# 適宜cookies.sqliteファイルまでのpathを編集
COOKIES = r"cookies.sqlite"
CONTENTS = "host, path, isSecure, expiry, name, value"
def read_cookies(host):
with sqlite3.connect(COOKIES) as conn:
cursor = conn.cursor()
sql = "SELECT {c} FROM moz_cookies WHERE host LIKE '%{h}%'".format(
c=CONTENTS, h=host)
cursor.execute(sql)
for item in cursor.fetchall():
print("host: {0}".format(item[0]))
print("path: {0}".format(item[1]))
print("isSecure: {0}".format(item[2]))
print("expiry: {0}".format(item[3]))
print("name: {0}".format(item[4]))
print("value: {0}".format(item[5]))
print("*"*30)
if __name__ == '__main__':
read_cookies("nicovideo")
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment