python操作谷歌浏览器,python获取chrome cookies

大家好,小编来为大家解答以下问题,python操作谷歌浏览器,python获取chrome cookies,现在让我们一起来看看吧!

Chrome浏览器已保存的密码都保存在一个sqlite3数据库文件中,和Cookies数据库在同一个文件夹。

如:C:\Users\Jueee\AppData\Local\Google\Chrome\User Data\Default\Login Data

前面的路径“C:\Users\Jueee\AppData\Local”,我们可以通过读取环境变量中的值来实现python中turtle画

解决方案:

使用微软自带的 CryptUnprotectData 函数解密数据库中的密码字段,即可还原密码。

CryptUnprotectData 函数可以在 win32crypt 中找到。

【注】为了防止出现读写出错,建议先把数据库临时拷贝到当前目录。

代码如下:

import os,sys
import shutil
import sqlite3
import win32crypt

db_file_path = os.path.join(os.environ['LOCALAPPDATA'],r'Google\Chrome\User Data\Default\Login Data')
print(db_file_path)

tmp_file = os.path.join(os.path.dirname(sys.executable),'tmp_tmp_tmp')
print(tmp_file)
if os.path.exists(tmp_file):
    os.remove(tmp_file)
shutil.copyfile(db_file_path,tmp_file)

conn = sqlite3.connect(tmp_file)
for row in conn.execute('select signon_realm,username_value,password_value from logins'):
    try:
        ret = win32crypt.CryptUnprotectData(row[2],None,None,None,0)
        print('网站:%-50s,用户名:%-20s,密码:%s' % (row[0][:50],row[1],ret[1].decode('gbk')))
    except Exception as e:
        print('获取Chrome密码失败...')
        raise e
conn.close()
os.remove(tmp_file)
 

运行结果:

账户和密码,就全部都通过明文方式展示出来啦。

GitHub 地址:https://github.com/Jueee/05-WebCrawlers/blob/master/14-ChromePassword.py

  • 3
    点赞
  • 10
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
可以使用Python的Selenium库来清理谷歌浏览器缓存。具体步骤如下: 1. 首先需要导入Selenium库和webdriver模块,以及ChromeOptions类和Options类。 ```python from selenium import webdriver from selenium.webdriver.chrome.options import Options ``` 2. 创建一个ChromeOptions对象,并设置浏览器参数。 ```python options = Options() options.add_argument('--ignore-certificate-errors') options.add_argument('--ignore-ssl-errors') ``` 3. 创建一个WebDriver对象,并使用ChromeOptions对象作为参数来设置浏览器参数。 ```python driver = webdriver.Chrome(chrome_options=options) ``` 4. 打开浏览器,并访问需要清理缓存的网站。 ```python driver.get('https://www.example.com') ``` 5. 使用execute_script()方法执行JavaScript代码来清理缓存。 ```python driver.execute_script('window.localStorage.clear();') driver.execute_script('window.sessionStorage.clear();') driver.execute_script('window.location.reload();') ``` 6. 关闭浏览器。 ```python driver.quit() ``` 完整的代码示例: ```python from selenium import webdriver from selenium.webdriver.chrome.options import Options options = Options() options.add_argument('--ignore-certificate-errors') options.add_argument('--ignore-ssl-errors') driver = webdriver.Chrome(chrome_options=options) driver.get('https://www.example.com') driver.execute_script('window.localStorage.clear();') driver.execute_script('window.sessionStorage.clear();') driver.execute_script('window.location.reload();') driver.quit() ``` 注意:这个方法只能清理浏览器缓存,不能清理浏览器历史记录和cookie等其他数据。如果需要清理其他数据,可以使用selenium的delete_all_cookies()方法来删除cookie。

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值