读取浏览器cookies的python脚本
时间: 2023-04-25 07:03:57 浏览: 110
以下是读取浏览器cookies的Python脚本:
```python
import sqlite3
import os
def get_cookies_from_chrome():
# 获取Chrome浏览器的cookies
cookies_file = os.path.expanduser('~') + r"\AppData\Local\Google\Chrome\User Data\Default\Cookies"
conn = sqlite3.connect(cookies_file)
cursor = conn.cursor()
cursor.execute("SELECT host_key, name, value FROM cookies")
cookies = cursor.fetchall()
conn.close()
return cookies
def get_cookies_from_firefox():
# 获取Firefox浏览器的cookies
cookies_file = os.path.expanduser('~') + r"\AppData\Roaming\Mozilla\Firefox\Profiles\*.default\cookies.sqlite"
conn = sqlite3.connect(cookies_file)
cursor = conn.cursor()
cursor.execute("SELECT host, name, value FROM moz_cookies")
cookies = cursor.fetchall()
conn.close()
return cookies
# 调用函数获取浏览器cookies
chrome_cookies = get_cookies_from_chrome()
firefox_cookies = get_cookies_from_firefox()
# 输出浏览器cookies
print("Chrome浏览器的cookies:")
for cookie in chrome_cookies:
print(cookie)
print("Firefox浏览器的cookies:")
for cookie in firefox_cookies:
print(cookie)
```
该脚本可以读取Chrome和Firefox浏览器的cookies,并将其输出到控制台。其中,Chrome浏览器的cookies文件路径为`C:\Users\用户名\AppData\Local\Google\Chrome\User Data\Default\Cookies`,Firefox浏览器的cookies文件路径为`C:\Users\用户名\AppData\Roaming\Mozilla\Firefox\Profiles\*.default\cookies.sqlite`。请将其中的`用户名`替换为您的Windows用户名。
阅读全文
相关推荐


















