Netscape-Bookmarks-File-Parser icon indicating copy to clipboard operation
Netscape-Bookmarks-File-Parser copied to clipboard

List index out of range

Open Tyrn opened this issue 4 years ago • 1 comments

Hi,

An attempt at parsing results in this error:

>>> ks = NetscapeBookmarksFile('static/html/example.html').parse()
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/home/user/spaces/python/fastapi-sidebar/.venv/lib/python3.9/site-packages/NetscapeBookmarksFileParser/
parser.py", line 228, in parse
    while '<' not in lines[line_num]:
IndexError: list index out of range
>>> 

Exactly the same error reported here.

Line 228:

    line_num = 0
    file = netscape_bookmarks_file
    lines = netscape_bookmarks_file.html.splitlines()

    while '<' not in lines[line_num]:                  # Line 228
        line_num += 1

The idea is not quite clear to me, but this conditional increment is obviously dangerous.

A reasonably short example, which produces this error can be found here

I am having the same error on a file exported from the Google Bookmarks service, which expires September 30. It's visible in the browser, so should be salvageable.

UPD

Oh, I'm sorry. It should have been

>>> with open('static/html/example.html') as file:
...     ks = NetscapeBookmarksFile(file).parse()
... 
>>> ks
<NetscapeBookmarksFileParser.NetscapeBookmarksFile object at 0x7f3de67d8040>

What can I do with this ks object? Can I make a dictionary of it?

Tyrn avatar Sep 30 '21 19:09 Tyrn

Sorry for the delayed response, university is being a heavy toll at the moment

This error is being addressed by #4. You're right, it's very unsafe and I'm in the process of fixing it.

You can find what the objects are made of in the classes section of the wiki. You could make a dictionary out of a NetscapeBookmarksFile by recursively iterating the BookmarkFolders objects inside of it and getting all the BookmarkShortcut objects on them. You can see some usage on the Bookmarks-to-Dir repo, although code quality there isn't that good

This project deeply needs an overhaul. I want to do that soon

FlyingWolFox avatar Nov 04 '21 14:11 FlyingWolFox