我正在开发一个应用程序,需要使用Chrome浏览器历史记录。我已经编写了C#代码来获取历史记录。但是我的代码有两个问题,我无法解决。
1.有一个警告。 警告1:正在构建的项目的处理器体系结构“MSIL”与引用“System.Data.SQLite”的处理器体系结构“AMD64”不匹配。此不匹配可能会导致运行时故障。请考虑通过配置管理器更改所选项目的目标处理器体系结构,以使项目和引用之间的处理器体系结构对齐,或者依赖于具有与项目的目标处理器体系结构匹配的处理器体系结构的引用。
2.有一个错误。 SQLite错误(5):数据库被锁定
我尝试关闭浏览器,但仍然出现这个错误。但是,当我创建了历史记录文件的副本并将其重命名,将其路径替换为History后,程序可以工作,并且可以读取文件并提取数据。 我无法确定错误在哪里。因此,请帮忙看一下,我将发布我的3个类文件。
1.有一个警告。 警告1:正在构建的项目的处理器体系结构“MSIL”与引用“System.Data.SQLite”的处理器体系结构“AMD64”不匹配。此不匹配可能会导致运行时故障。请考虑通过配置管理器更改所选项目的目标处理器体系结构,以使项目和引用之间的处理器体系结构对齐,或者依赖于具有与项目的目标处理器体系结构匹配的处理器体系结构的引用。
2.有一个错误。 SQLite错误(5):数据库被锁定
我尝试关闭浏览器,但仍然出现这个错误。但是,当我创建了历史记录文件的副本并将其重命名,将其路径替换为History后,程序可以工作,并且可以读取文件并提取数据。 我无法确定错误在哪里。因此,请帮忙看一下,我将发布我的3个类文件。
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.IO;
using System.Data.SQLite;
using System.Data;
namespace ChromeData
{
class GoogleChrome
{
public List<URL> Urls = new List<URL>();
public IEnumerable<URL> GetHistory()
{
string DocumentsFolder = Environment.GetFolderPath(Environment.SpecialFolder.LocalApplicationData);
//Console.WriteLine(DocumentsFolder);
string[] tempstr = DocumentsFolder.Split('\\');
foreach(string s in tempstr)
{
Console.WriteLine(s);
}
string tempstr1 = "";
DocumentsFolder += "\\Google\\Chrome\\User Data\\Default";
if(tempstr[tempstr.Length-1] != "Local")
{
for(int i =0; i<tempstr.Length-1;i++)
{
tempstr1 += tempstr[i] + "\\";
}
DocumentsFolder = tempstr1 + "Local\\Google\\Chrome\\User Data\\Default";
}
Console.WriteLine(DocumentsFolder);
if(Directory.Exists(DocumentsFolder))
{
return ExtractUserHistory(DocumentsFolder);
}
return null;
}
public IEnumerable<URL> ExtractUserHistory(string folder)
{
DataTable HistoryData = ExtractFromTable("urls", folder);
foreach(DataRow row in HistoryData.Rows)
{
string url = row["url"].ToString();
string title = row["title"].ToString();
URL u = new URL(url.Replace('\'',' '), title.Replace('\'',' '), "Google Chrome");
Urls.Add(u);
}
return Urls;
}
DataTable ExtractFromTable(string table, string folder)
{
SQLiteConnection sql_con;
SQLiteDataAdapter DB;
SQLiteCommand sql_cmd;
string dbpath = folder + "\\History";
DataTable DT = new DataTable();
if(File.Exists(dbpath))
{
try
{
sql_con = new SQLiteConnection("Data Source=" + dbpath + ";Version=3;New=False;Compress=True;");
sql_con.Open();
sql_cmd = sql_con.CreateCommand();
string CommandText = "select * from " + table;
DB = new SQLiteDataAdapter(CommandText, sql_con);
DB.Fill(DT);
sql_con.Close();
}
catch(Exception e)
{
TextWriter errorWriter = Console.Error;
errorWriter.WriteLine(e.Message);
}
}
return DT;
}
}
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.IO;
namespace ChromeData
{
class TestClass
{
public static List<URL> Urls = new List<URL>();
public static void Main()
{
string path = @"C:\Users\Public\Desktop\history.txt";
GoogleChrome g = new GoogleChrome();
Urls = (List<URL>)g.GetHistory();
using(StreamWriter sw = File.CreateText(path))
{
foreach(URL u in Urls)
{
sw.WriteLine(u.url);
}
}
Console.ReadLine();
}
}
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace ChromeData
{
class URL
{
public string url;
public string title;
public string browser;
public URL(string url,string title,string browser)
{
this.browser = browser;
this.title = title;
this.url = url;
}
}