Ecosyste.ms: Awesome

An open API service indexing awesome lists of open source software.

Awesome Lists | Featured Topics | Projects

https://github.com/FlyingWolFox/Netscape-Bookmarks-File-Parser

Parser and creator for Netscape Bookmarks file format that is used when exporting bookmarks from browsers
https://github.com/FlyingWolFox/Netscape-Bookmarks-File-Parser

bookmarks browser create exporting-bookmarks generate netscape netscape-bookmark netscape-bookmark-file parse-bookmarks parse-netscape parse-netscape-bookmarks-file parse-netscape-bookmarks-file-1 parser

Last synced: about 2 months ago
JSON representation

Parser and creator for Netscape Bookmarks file format that is used when exporting bookmarks from browsers

Awesome Lists containing this project

README

        

# Netscape Bookmarks File Parser

This is a parser for the Netscape Bookmarks file format, which is generated by browsers when exporting bookmarks to html. It parses the file and delivers an object representing the file with the bookmark structure of folders and shortcuts as objects too. The folder tree can be navigated using the "." notation. It an also create a Netscape Bookmarks file.

## Installation

Run this in your command line (might need to run as administrator on Windows):

```bash
pip install git+https://github.com/FlyingWolFox/Netscape-Bookmarks-File-Parser.git
```

To update add the `--upgrade` flag to the end

## How to use

Import the classes and the parser:

```python
from NetscapeBookmarksFileParser import *
from NetscapeBookmarksFileParser import parser # if you want to parse a file
```

If you want to create a file, import the creator as well:

```python
from NetscapeBookmarksFileParser import creator # if you want to create a file
```

then:

```python
bookmarks = NetscapeBookmarksFile(file).parse()
```

Where `file` is a string with the file contents or a file opened with `open()`, e.g.:

```python
with open('bookmarks.html') as file:
bookmarks = NetscapeBookmarksFile(file)
```

or:

```python
with open('bookmarks.html') as file:
bookmarks = NetscapeBookmarksFile(file.read())
```

If you want to create a file, create the bookmark structure and call `create_file()`.

To know about the classes that the parser and the creator will work with, see the [wiki Classes section](https://github.com/FlyingWolFox/Netscape-Bookmarks-File-Parser/wiki/Code-Documentation#classes).

## Quick Example

```python
from NetscapeBookmarksFileParser import *
from NetscapeBookmarksFileParser import parser

with open('bookmarks.html') as file:
bookmarks = NetscapeBookmarksFile(file).parse()

root_folder = bookmarks.bookmarks
print(bookmarks.title) # print the file's title
print(root_folder.items[0].name) # print the name of the first item on the root folder
print(root_folder.shortcuts[1].href) # print the url of the first shortcut on the root folder
print(root_folder.children[0].personal_toolbar) # print if the first children folder is the Bookmarks Toolbar
```

## Notice about this parser

The parser will play like a browser and will ignore most errors and warn for some missing tags. If a folder has an opening ``, but no closing ``, an exception will be raised. Since Netscape Bookmarks files are commonly generated by browsers when exporting bookmarks in html, these warnings and exceptions shouldn't be common. This parser was based on [Microsoft's documentation on the Netscape File Format](https://docs.microsoft.com/en-us/previous-versions/windows/internet-explorer/ie-developer/platform-apis/aa753582(v=vs.85)?redirectedfrom=MSDN) mainly, but also on file examples ([here](https://sixtwothree.org/posts/homesteading-a-decades-worth-of-shared-links), [here](https://stackoverflow.com/questions/38029954/parse-a-netscape-style-bookmarks-html-file-into-nested-array), [here](https://gist.github.com/jgarber623/cdc8e2fa1cbcb6889872) and [here](https://www.npmjs.com/package/netscape-bookmarks)) and my own browser exports (`test\test.html` is one of them). Some more uncommon attributes and items might not be supported. See the [Attributes Supported](https://github.com/FlyingWolFox/Netscape-Bookmarks-File-Parser/wiki/The-Parser#attributes-supported) and [Items Supported](https://github.com/FlyingWolFox/Netscape-Bookmarks-File-Parser/wiki/The-Parser#items-supported) sections in the wiki. If you want to know more about what a file needs to have to be accepted by the parser, read the [Netscape Bookmarks File Format page](https://github.com/FlyingWolFox/Netscape-Bookmarks-File-Parser/wiki/Netscape-Bookmarks-File-Format) in the wiki.

## Notice about the creator

The creator is the parser in reverse. If you parse a file and create it again, if all lines are valid, the files will be equal. You can see this with `test/test.html` and `test/created_file.html`. The first was parsed, then the creation process created the second. Look at the [wiki Creator page]() to know more about the creator.

## About legacy support

Due to the Netscape Bookmark file format not having an official standard, many things of this parser was got by file examples in the internet (see the [Nestcape Bookmarks File format](https://github.com/FlyingWolFox/Netscape-Bookmarks-File-Parser/wiki/Netscape-Bookmarks-File-Format) and [The parser](https://github.com/FlyingWolFox/Netscape-Bookmarks-File-Parser/wiki/The-Parser) in the wiki). This has legacy support for some types of items that aren't in use today. These are:

- Feed: Probably RSS feeds, just some attributes following the Microsoft's Documentation
- Web Slices: "Live bookmarks". They showed a piece of the page you saved. Extinct but in the Microsoft's Documentation. If you want more details look at the [Legacy section](https://github.com/FlyingWolFox/Netscape-Bookmarks-File-Parser/wiki/The-Parser#about-legacybasic-support) in the wiki

## Help

- If you would like to report a bug or ask a question please [open an issue](https://github.com/FlyingWolFox/Netscape-Bookmarks-File-Parser/issues/new).
- If you would like to help this project, you can open a Pull Request
- If you want more information about this project, have a look at the [wiki](https://github.com/FlyingWolFox/Netscape-Bookmarks-File-Parser/wiki)