如何將瀏覽器書籤單獨儲存到PC資料夾中?

如何將瀏覽器書籤單獨儲存到PC資料夾中?

我目前正在使用 Brave 瀏覽器。我有很多書籤,想將它們下載到我電腦上的資料夾中,但作為單獨的連結。

我怎樣才能做到這一點?

我已成功匯出所有書籤,但它保存為單一 html 檔案。也許有一種方法可以分析文件並單獨保存連結?

答案1

我編寫了一個快速的 PowerShell 腳本來為您完成此操作。您需要更新$bookmarks_file$bookmarks_folder指向您需要的位置。

不幸的是,這僅適用於 Windows,對 Mac 沒有幫助,因為 Mac 有不同的捷徑格式,而且我沒有 Mac 可以測試。

$bookmarks_file = "bookmarks.html"
$bookmarks_folder = "C:\Users\Someone\Desktop\Shortcuts"
$matches = Get-Content $bookmarks_file -Raw | Select-String -Pattern 'HREF="([^"]*)"[^>]*>([^<]*)<'  -AllMatches | % { $_.Matches }

foreach ($match in $matches) {
    Write-Host $match.Groups[1].Value' '$match.groups[2].Value
    $filename = $match.groups[2].Value
    $invalidChars = [IO.Path]::GetInvalidFileNameChars() -join ''
    $re = "[{0}]" -f [RegEx]::Escape($invalidChars)
    $filename = $filename -replace $re
    $location = "$($bookmarks_folder)\\$($filename).lnk"
    $WshShell = New-Object -ComObject WScript.Shell
    $Shortcut = $WshShell.CreateShortcut("$location")
    $Shortcut.TargetPath = $match.Groups[1].Value
    $Shortcut.Save()
}

解釋

  • $matches = Get-Content $bookmarks_file -Raw | Select-String -Pattern 'HREF="([^"]*)"[^>]*>([^<]*)<' -AllMatches | % { $_.Matches }

    此行將文件中的連結和連結標題讀取bookmarks.html到數組中。

  • foreach ($match in $matches)將查看數組

  • Write-Host $match.Groups[1].Value' '$match.groups[2].Value將 URL 和標題寫入控制台以供參考
  • $filename = $match.groups[2].Value將收藏夾的標題儲存為檔案名
  • $invalidChars = [IO.Path]::GetInvalidFileNameChars() -join '' $re = "[{0}]" -f [RegEx]::Escape($invalidChars) $filename = $filename -replace $re替換檔案名稱中的任何非法字符
  • $location = "$($bookmarks_folder)\\$($filename).lnk"建立完整路徑,包括目錄
  • $WshShell = New-Object -ComObject WScript.Shell $Shortcut = $WshShell.CreateShortcut("$location") $Shortcut.TargetPath = $match.Groups[1].Value $Shortcut.Save()使用產生的文件路徑和 URL 建立快捷方式

相關內容