Chrome Cookies獲取


 1 import os
 2 import sqlite3
 3 import requests
 4 from win32.win32crypt import CryptUnprotectData
 5 
 6 def getchromecookie(host):
 7     cookiepath = os.environ['LOCALAPPDATA'] + r"\Google\Chrome\User Data\Default\Cookies"
 8     with sqlite3.connect(cookiepath) as conn:
 9         sqlite = "select host_key,name,encrypted_value from cookies where host_key='%s'"%host
10         cu = conn.cursor()
11         '''自己寫的'''
12         cursor = cu.execute(sqlite)
13         # for row in cursor:
14         #     cookies = {row[1]:CryptUnprotectData(row[2])}
15         #     print(row)
16         #     print(cookies)
17         '''網上找的'''
18         '''Python查詢Mysql使用 fetchone() 方法獲取單條數據, 使用fetchall() 方法獲取多條數據。'''
19         '''Python decode() 方法以 encoding 指定的編碼格式解碼字符串。默認編碼為字符串編碼。'''
20         # cookies = {name: CryptUnprotectData(encrypted_value)[1].decode() for host_key, name, encrypted_value in
21         #            cu.execute(sqlite).fetchall()}
22         # print(cookies)
23         '''再改一下'''
24         for host_key,name,encrypted_value in cursor:
25             cookies = {name:CryptUnprotectData(encrypted_value)[1].decode()}
26             return cookies
27 host = 'sp.kaixintuba.com'
28 # print(getchromecookie(host))
29 url = 'http://sp.kaixintuba.com/manager/vm_offline.aspx?_r=636014316'
30 r = requests.get(url,cookies = getchromecookie(host))
31 print(r.text)

 


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM