Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

List index out of range #6

Open
Tyrn opened this issue Sep 30, 2021 · 1 comment
Open

List index out of range #6

Tyrn opened this issue Sep 30, 2021 · 1 comment

Comments

@Tyrn
Copy link

Tyrn commented Sep 30, 2021

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?

@FlyingWolFox
Copy link
Owner

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants