使用 C# 读取 Firefox 书签

发布于 2024-07-22 05:06:59 字数 533 浏览 17 评论 0原文

使用 C#,我需要获取所有 Firefox 书签,以便将它们导入到我们的数据库中。 我怎样才能做到这一点?

我知道这个问题,Read FF 3 bookmarks in Java,但是那里的答案所有这些似乎都围绕 Java 数据库驱动程序,并且我不确定其中一些答案是否不是特定于 Java 的。

我的主要问题是,“如何用 C# 读取 Firefox 书签?”

第二个问题:我看到 \%user profile%\application data\mozilla\firefox\profiles\bookmarkbackups\bookmarks-[date].json 文件 - 我可以解析它吗? 如果是这样,是否有现有的解析器?

反问:为什么这不能像 IE 那样简单,我只是读取 \%user profile%\favorites 中的 .url 文件? 呸。

Using C#, I need to get all Firefox bookmarks for importing them into our database. How can I do this?

I'm aware of the SO question, Read FF 3 bookmarks in Java, but the answers there all seem to revolve around Java database drivers, and I'm not sure that some of those answers aren't Java-specific.

My primary question is, "How can I read Firefox bookmarks in C#?"

Secondary questions: I see \%user profile%\application data\mozilla\firefox\profiles\bookmarkbackups\bookmarks-[date].json files -- can I just parse that? If so, are there any existing parsers for that?

Rhetorical lamenting question: Why can't this be as easy as IE, where I just read the .url files in \%user profile%\favorites? Bah.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(5

飘过的浮云 2024-07-29 05:06:59

使用适用于 .Net 的 SQLite 驱动程序并访问文件 places.sqlite,该文件位于
应用程序数据/Mozilla/Firefox/Profiles/$this_varies/places.sqlite

在我的电脑上。 您应该不难在目标计算机上找到它。

编辑1:
下面是从数据库打印出 url 的代码片段:

using System.Data.SQLite; // downloaded from http://sourceforge.net/projects/adodotnetsqlite

namespace sqlite_test
{
    class Program
    {
        static void Main(string[] args)
        {
            var path_to_db = @"C:\places.sqlite"; // copied here to avoid long path
            SQLiteConnection sqlite_connection = new SQLiteConnection("Data Source=" + path_to_db + ";Version=3;New=True;Compress=True;");

            SQLiteCommand sqlite_command = sqlite_connection.CreateCommand();

            sqlite_connection.Open();

            sqlite_command.CommandText = "select * from moz_places";

            SQLiteDataReader sqlite_datareader = sqlite_command.ExecuteReader();

            while (sqlite_datareader.Read())
            {
                // Prints out the url field from the table:
                System.Console.WriteLine(sqlite_datareader["url"]);
            }
        }
    }
}

编辑 2:
作为小费。 我真的必须推荐 Firefox 的 SQLite Manager 插件。 它对于使用 sqlite 数据库非常有用。

Use the SQLite driver for .Net and access the file places.sqlite it can be found at
Application Data/Mozilla/Firefox/Profiles/$this_varies/places.sqlite

on my computer. It should not be hard for you to locate on your target computers.

Edit 1:
Here is a snip of code that prints out urls from the database:

using System.Data.SQLite; // downloaded from http://sourceforge.net/projects/adodotnetsqlite

namespace sqlite_test
{
    class Program
    {
        static void Main(string[] args)
        {
            var path_to_db = @"C:\places.sqlite"; // copied here to avoid long path
            SQLiteConnection sqlite_connection = new SQLiteConnection("Data Source=" + path_to_db + ";Version=3;New=True;Compress=True;");

            SQLiteCommand sqlite_command = sqlite_connection.CreateCommand();

            sqlite_connection.Open();

            sqlite_command.CommandText = "select * from moz_places";

            SQLiteDataReader sqlite_datareader = sqlite_command.ExecuteReader();

            while (sqlite_datareader.Read())
            {
                // Prints out the url field from the table:
                System.Console.WriteLine(sqlite_datareader["url"]);
            }
        }
    }
}

Edit 2:
As tip. I really must recommend the SQLite Manager plugin for firefox. It's very useful for working with sqlite databases.

君勿笑 2024-07-29 05:06:59

当然,它的工作方式与 Java 问题中建议的方式相同,只需获取 SQLite .NET 提供程序 并使用它访问 FF 数据库文件。

Surely it works the same way as suggested in the Java question, just get the SQLite .NET provider and use that to access the FF database file.

不爱素颜 2024-07-29 05:06:59

有一个适用于 .Net 的 SQLite 驱动程序。 一旦你开始工作,我想解决方案在 .Net 和 Java 中都是相同的。

There's a SQLite driver for .Net. Once you get that working I'd imagine the solution would be the same in both .Net and Java.

十年九夏 2024-07-29 05:06:59

我必须为我的项目http://www.codertakeout.com稍微修改一下。 希望这次修订有助于澄清一些事情,感谢网络上的一些建议。

using System.Data.SQLite;  // need to install sqlite .net driver

String path_to_db = @"C:\Documents and Settings\Jeff\Application Data\Mozilla\Firefox\Profiles\yhwx4xco.default\places.sqlite";
String path_to_temp = System.IO.Path.GetTempFileName();

System.IO.File.Copy(path_to_db, path_to_temp, true);
SQLiteConnection sqlite_connection = new SQLiteConnection("Data Source=" + path_to_temp + ";Version=3;Compress=True;Read Only=True;");

SQLiteCommand sqlite_command = sqlite_connection.CreateCommand();

sqlite_connection.Open();

sqlite_command.CommandText = "SELECT moz_bookmarks.title,moz_places.url FROM moz_bookmarks LEFT JOIN moz_places WHERE moz_bookmarks.fk = moz_places.id AND moz_bookmarks.title != 'null' AND moz_places.url LIKE '%http%';";

SQLiteDataReader sqlite_datareader = sqlite_command.ExecuteReader();

while (sqlite_datareader.Read())
    {
        System.Console.WriteLine(sqlite_datareader[1]);
    }
sqlite_connection.Close();
System.IO.File.Delete(path_to_temp);

I had to rework this slightly for my project http://www.codertakeout.com. Hope this revision helps clarify a few things thanks to some suggestions from around the web.

using System.Data.SQLite;  // need to install sqlite .net driver

String path_to_db = @"C:\Documents and Settings\Jeff\Application Data\Mozilla\Firefox\Profiles\yhwx4xco.default\places.sqlite";
String path_to_temp = System.IO.Path.GetTempFileName();

System.IO.File.Copy(path_to_db, path_to_temp, true);
SQLiteConnection sqlite_connection = new SQLiteConnection("Data Source=" + path_to_temp + ";Version=3;Compress=True;Read Only=True;");

SQLiteCommand sqlite_command = sqlite_connection.CreateCommand();

sqlite_connection.Open();

sqlite_command.CommandText = "SELECT moz_bookmarks.title,moz_places.url FROM moz_bookmarks LEFT JOIN moz_places WHERE moz_bookmarks.fk = moz_places.id AND moz_bookmarks.title != 'null' AND moz_places.url LIKE '%http%';";

SQLiteDataReader sqlite_datareader = sqlite_command.ExecuteReader();

while (sqlite_datareader.Read())
    {
        System.Console.WriteLine(sqlite_datareader[1]);
    }
sqlite_connection.Close();
System.IO.File.Delete(path_to_temp);
黎歌 2024-07-29 05:06:59

访问http://myexps.blogspot.com了解java中的实现。

import java.sql.*;

public class helloWorld {
  public static void main(String[] args) throws Exception {
      Class.forName("org.sqlite.JDBC");
      Connection conn = DriverManager.getConnection("jdbc:sqlite:/home/deepak/.mozilla/firefox/yvf7p20d.default/places.sqlite//");
  if(conn==null)
  {
   System.out.println("ERROR");
  }
  System.out.println(conn.toString());

  Statement stat = conn.createStatement();

  ResultSet rs = stat.executeQuery("select * from moz_bookmarks;");
  while (rs.next()) {
      System.out.println("id = " + rs.getString("id"));
      System.out.println("keyword = " + rs.getString("keyword_id"));
      System.out.println("title = " + rs.getString("title"));
  }
  rs.close();
  conn.close();
  }
}

这将是java实现

Visit http://myexps.blogspot.com for the implementation in java.

import java.sql.*;

public class helloWorld {
  public static void main(String[] args) throws Exception {
      Class.forName("org.sqlite.JDBC");
      Connection conn = DriverManager.getConnection("jdbc:sqlite:/home/deepak/.mozilla/firefox/yvf7p20d.default/places.sqlite//");
  if(conn==null)
  {
   System.out.println("ERROR");
  }
  System.out.println(conn.toString());

  Statement stat = conn.createStatement();

  ResultSet rs = stat.executeQuery("select * from moz_bookmarks;");
  while (rs.next()) {
      System.out.println("id = " + rs.getString("id"));
      System.out.println("keyword = " + rs.getString("keyword_id"));
      System.out.println("title = " + rs.getString("title"));
  }
  rs.close();
  conn.close();
  }
}

This will be the java implementation

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文