獲取谷歌瀏覽器cookie的兩種方法


一、讀取瀏覽器的中文件獲取,使用sqlite3

import sqlite3
import win32crypt
username = os.environ.get('USERNAME')
cookie_file = 'C:/Users/{UserName}/AppData/Local/Google/Chrome/User Data/Default/Cookies'.format(UserName=username)
con = sqlite3.connect(cookie_file)
cursor = con.cursor()
sql = 'SELECT host_key, name, value, encrypted_value FROM cookies WHERE name = "xxxxx" and host_key="xxxxx";'try:
  if cursor.execute(sql):
     for en_value in cursor:
         pwdHash = en_value[3]
                if pwdHash:
                    ret = win32crypt.CryptUnprotectData(pwdHash, None, None, None, 0)#解密
                    a = bytes.decode(ret[1])except Exception as e:
            print(e)

 

二、使用selenium

from selenium import webdriver

driver = webdriver.Chrome()  # 打開谷歌瀏覽器, 
driver.get('https://baidu.com')
cookie = driver.get_cookies()
driver.quit()

 


免責聲明!

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



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