如何从Delphi应用程序中获取Firefox书签?

如何从Delphi应用程序中获取Firefox书签?,delphi,firefox,sqlite,Delphi,Firefox,Sqlite,我知道如何从IE中获取收藏夹,但如何访问Firefox的书签 以下是我用于检索IE收藏夹的代码: uses ShlObj, ActiveX; function GetIEFavourites(const favpath: string): TStrings; var searchrec: TSearchRec; str: TStrings; path, dir, FileName: string; Buffer: array[0..2047] of Char; foun

我知道如何从IE中获取收藏夹,但如何访问Firefox的书签

以下是我用于检索IE收藏夹的代码:

uses
  ShlObj, ActiveX;

function GetIEFavourites(const favpath: string): TStrings;
var
  searchrec: TSearchRec;
  str: TStrings;
  path, dir, FileName: string;
  Buffer: array[0..2047] of Char;
  found: Integer;
begin
  str := TStringList.Create;
  // Get all file names in the favourites path
  path  := FavPath + '\*.url';
  dir   := ExtractFilepath(path);
  found := FindFirst(path, faAnyFile, searchrec);
  while found = 0 do
  begin
    // Get now URLs from files in variable files
    Setstring(FileName, Buffer, GetPrivateProfilestring('InternetShortcut',
      PChar('URL'), nil, Buffer, SizeOf(Buffer), PChar(dir + searchrec.Name)));
    str.Add(FileName);
    found := FindNext(searchrec);
  end;
  // find Subfolders
  found := FindFirst(dir + '\*.*', faAnyFile, searchrec);
  while found = 0 do
  begin
    if ((searchrec.Attr and faDirectory) > 0) and (searchrec.Name[1] <> '.') then
      str.Addstrings(GetIEFavourites(dir + '\' + searchrec.Name));
    found := FindNext(searchrec);
  end;
  FindClose(searchrec);
  Result := str;
end;

procedure FreePidl(pidl: PItemIDList);
var
  allocator: IMalloc;
begin
  if Succeeded(SHGetMalloc(allocator)) then
  begin
    allocator.Free(pidl);
    {$IFDEF VER100}
    allocator.Release;
    {$ENDIF}
  end;
end;

procedure TForm1.Button1Click(Sender: TObject);
var
  pidl: PItemIDList;
  FavPath: array[0..MAX_PATH] of Char;
begin
  if Succeeded(ShGetSpecialFolderLocation(Handle, CSIDL_FAVORITES, pidl)) then
  begin
    if ShGetPathfromIDList(pidl, FavPath) then
      ListBox1.Items := GetIEFavourites(StrPas(FavPath));
    // The calling application is responsible for freeing the PItemIDList-pointer
    // with the Shell's IMalloc interface
    FreePIDL(pidl);
  end;
end;
使用
ShlObj,ActiveX;
函数getiefavorites(constfavpath:string):TStrings;
变量
searchrec:TSearchRec;
str:TStrings;
路径,目录,文件名:字符串;
缓冲区:字符的数组[0..2047];
发现:整数;
开始
str:=TStringList.Create;
//获取收藏夹路径中的所有文件名
路径:=FavPath+'\*.url';
dir:=ExtractFilepath(路径);
找到:=FindFirst(路径、faAnyFile、searchrec);
当发现=0时,执行以下操作
开始
//现在从变量文件中的文件获取URL
Setstring(文件名、缓冲区、GetPrivateProfilestring('InternetShortcut'),
PChar('URL')、nil、Buffer、SizeOf(Buffer)、PChar(dir+searchrec.Name));
str.Add(文件名);
找到:=FindNext(searchrec);
结束;
//查找子文件夹
找到:=FindFirst(dir+'\*.*',faAnyFile,searchrec);
当发现=0时,执行以下操作
开始
如果((searchrec.Attr和faDirectory)>0)和(searchrec.Name[1]'.'),则
str.Addstrings(getiefavorites(dir+'\'+searchrec.Name));
找到:=FindNext(searchrec);
结束;
FindClose(searchrec);
结果:=str;
结束;
程序自由pidl(pidl:PItemIDList);
变量
分配器:IMalloc;
开始
如果成功(SHGetMalloc(分配器)),则
开始
无分配器(pidl);
{$IFDEF VER100}
分配器。释放;
{$ENDIF}
结束;
结束;
程序TForm1.按钮1单击(发送方:TObject);
变量
pidl:PItemIDList;
FavPath:字符的数组[0..MAX_PATH];
开始
如果成功(ShGetSpecialFolderLocation(句柄、CSIDL_收藏夹、pidl)),则
开始
如果ShGetPathfromIDList(pidl,FavPath),则
ListBox1.Items:=getiefavorites(StrPas(FavPath));
//调用应用程序负责释放PItemIDList指针
//使用Shell的IMalloc接口
FreePIDL(pidl);
结束;
结束;

谢谢。

好吧,Firefox书签是存储在
\Application Data\Mozilla\Firefox\Profiles\
正如西南努尔所说的那样

因此,您需要获取mozilla profiles目录并重试该文件夹 名字在里面

之后,您需要解析html文件


所以说,不,没有API可以直接获取FF书签。

TBookmarks组件来自元产品。。。不过75美元:

从他们的网站上引用:

对于Borland Delphi 2,3,4,5,6,7,2005,2006,2007,2009

新的!支持Firefox3、Safari和Google Chrome书签

MetaProducts TBookmarks是Delphi 2-72005-2009组件,可帮助您在菜单中显示MS Internet Explorer收藏夹(4.0-8.0)、MSN Explorer、Opera热列表(3.0-9.0)和Netscape、Safari、Chrome、FireFox和Mozilla书签(2.0-8.0)

只需将TBookmarks组件放到表单上,并分配其菜单属性和OnURL事件。将Enabled设置为True以收集指定项目中的所有书签信息


您还可以使用TTreeView组件使TBookmarks自动填充其中的条目。

收藏夹保存在配置文件文件夹中的“places.sqlite”中。它们位于表moz_书签中。它们引用表moz_places中的条目及其字段fk。获取dll和类似的delphi绑定

使用SQLite3\u Open打开数据库,并使用SQLite3\u Exec发送普通sql语句来访问数据,如

SELECT * FROM moz_bookmarks;

不幸的是,firefox锁定了places.sqlite,这意味着您必须先复制它(普通文件复制)。处理完副本后,您可以将其删除。

您是否意识到Firefox书签可以在C:\Documents and Settings\user\Application Data\Mozilla\Firefox\Profiles\asdkjfh.default\bookmarks.HTMLM中找到,可能他没有,Sinan。请随意发布一个答案,演示如何获取该文件,然后从中提取书签。当我尝试使用sqlite3命令行程序时,我被禁止访问places.sqlite文件。它说数据库被锁定了;我想这是因为Firefox仍在运行。其他使用DLL的程序可能也会有同样的问题吗?是的,Firefox会对文件进行锁定,您需要先复制它,然后再使用副本。您可以在Firefox运行时复制它。