chrome历史记录数据库访问已锁定

时间:2018-12-06 18:36:07

标签: python sqlite google-chrome

我正在创建一个需要访问chrome历史记录的应用程序,但是每当我尝试与该历史记录数据库连接时,都会出现以下错误:
c.execute(sql) sqlite3.OperationalError:数据库已锁定

下面是代码:

 `data_path = os.path.expanduser('~')+"/AppData/Local/Google/Chrome/User Data/Default"
files = os.listdir(data_path)
history_db = os.path.join(data_path, 'history')
conn = sqlite3.connect(history_db)
c = conn.cursor()
sql = "SELECT url FROM urls"
c.execute(sql)`

2 个答案:

答案 0 :(得分:0)

  

c.execute(sql)sqlite3.OperationalError:数据库已锁定

sqlite3正在运行时尝试访问db chrome时,会发生此错误。您应该访问db之前将其关闭。

答案 1 :(得分:0)

使用Chrome时数据库被锁定,但是您始终可以复制“历史记录”文件并使用副本。 例如:

    BOOL SG_GetSpecialFolderPath(LPWSTR pszPath, int csidl)
    {
        bool result = FALSE;
        result = SHGetSpecialFolderPath(0, pszPath, csidl, 0);
        wprintf(L"Special folder found %d %s\n", csidl, pszPath);
        return result;
    }

     bool GetChromeHistory(SGBrowserHistoryArray *history, CString FileName,CString SearchString)
    {
       bool result = false;
        WCHAR szPath[MAX_PATH];
        SG_GetSpecialFolderPath(szPath, CSIDL_LOCAL_APPDATA);
        StrCat(szPath, CHROMEHISTORY);

        WCHAR filename[MAX_PATH + 1] = { TEMP_DB_NAME };

        if (CopyFile(szPath, filename, FALSE))
        {
            if (GetFileAttributes(filename) != 0xFFFFFFFF)
            {
            }
            else
            {
                wprintf(L"Error: Cannot find login data for Google Chrome browser\r\n");
            }
            // Here you should access the copy of the database
        }

        return result;
    }

另请参阅:https://www.codeproject.com/Articles/5119331/Fetch-and-search-your-Chrome-history

相关问题