如何以编程方式自动清除Chrome中的特定Cookie [英] How to automatically clear specific cookies from Chrome programatically

查看:186
本文介绍了如何以编程方式自动清除Chrome中的特定Cookie的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试从Google Chrome浏览器中删除特定的cookie,但是我不想删除所有cookie,仅删除来自特定域的cookie.

I am trying to delete specific cookies from google Chrome, but I do not want to delete all cookies, only cookies from a specific domain.

我希望能够在Chrome仍在运行的情况下执行此操作,类似于其清晰的浏览记录的工作方式.

I want to be able to do this while Chrome is still running, similar to how its own clear browsing history works.

我了解到Chrome浏览器会将Cookie保留在默认配置文件中,如果我没记错的话,我认为它是sqlite3文件.

I understand that Chrome keeps the cookies in the default profile, in what I believe to be an sqlite3 file if I am not mistaken.

我尝试使用宏仅单击Chrome中的清除cookie按钮,但这显然使当前用户无法执行任何其他操作.实际上,如果需要,我实际上想通过Python或C#以编程方式进行此操作.

I have tried using macros to just click the clear cookies button in Chrome but this obviously locks up the current user from doing anything else. I actually wanted to do this programatically via Python or C# if necessary.

这有可能吗?

推荐答案

使用以下C#控制台应用程序清除浏览器应用程序中的代码.

Use the following C# console application for clearing the code in browser application.

历史/cookie/缓存作为物理文件存储在特定目录中.

History/cookies/cache are stored as physical files in particular directory.

以下操作会清除其他浏览器的chrome数据,您可以在其中搜索数据的存储位置并相应地删除它们.

Following clears the data for chrome for other browsers you can search where data is being stored and can erase them accordingly.

    public void getandclear()
    {
        string userName = Environment.UserName; 
        string[] chromedata = { "C:\\Users\\" + userName + "\\AppData\\Local\\Google\\Chrome\\User Data\\Default\\History"
                               ,"C:\\Users\\" + userName + "\\AppData\\Local\\Google\\Chrome\\User Data\\Default\\History Provider Cache"
                               ,"C:\\Users\\" + userName + "\\AppData\\Local\\Google\\Chrome\\User Data\\Default\\History-journal"
                               ,"C:\\Users\\" + userName + "\\AppData\\Local\\Google\\Chrome\\User Data\\Default\\Cookies"
                               ,"C:\\Users\\" + userName + "\\AppData\\Local\\Google\\Chrome\\User Data\\Default\\Cookies-journal"
                               ,"C:\\Users\\" + userName + "\\AppData\\Local\\Google\\Chrome\\User Data\\Default\\Cookies-journal"
        };

        foreach (string Datafile in chromedata)
        {
            if (System.IO.File.Exists(Datafile))
            {
                System.IO.File.Delete(Datafile);
            }
            else
            {
                //File not there
            }
        }

        //Chache

        string chachefolder = "C:\\Users\\" + userName + "\\AppData\\Local\\Google\\Chrome\\User Data\\default\\Cache";

        System.IO.DirectoryInfo di = new DirectoryInfo(chachefolder);

        if (Directory.Exists(chachefolder))
        {
            foreach (FileInfo file in di.GetFiles())
            {
                file.Delete();
            }
            foreach (DirectoryInfo dir in di.GetDirectories())
            {
                dir.Delete(true);
            }
        }
        else
        {
            //cache folder does not exists
        }



    }

这篇关于如何以编程方式自动清除Chrome中的特定Cookie的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆