# Buggy code
def get_image_bookmark(hide, start_page=1, end_page=0, tag="", sorting=None):
    """Get user's image bookmark"""
    total_list = list()
    i = start_page
    while True:
        if end_page != 0 and i > end_page:
            print("Page Limit reached: " + str(end_page))
            break

        url = "https://www.pixiv.net/bookmark.php?p=" + str(i)
        if hide:
            url = url + "&rest=hide"
        # Implement #468 default is desc, only for your own bookmark.
        if sorting in ("asc", "date_d", "date"):
            url = url + "&order=" + sorting
        if tag is not None and len(tag) > 0:
            url = url + "&tag=" + PixivHelper.encode_tags(tag)
        PixivHelper.print_and_log(
            "info", "Importing user's bookmarked image from page " + str(i)
        )
        PixivHelper.print_and_log("info", "Source URL: " + url)

        page = __br__.open(url)
        parse_page = BeautifulSoup(page.read().decode("utf-8"), features="html5lib")
        bookmarks = PixivBookmark.parseImageBookmark(parse_page)
        total_list.extend(bookmarks)
        if len(bookmarks) == 0:
            print("No more images.")
            break
        else:
            print(" found " + str(len(bookmarks)) + " images.")

        i = i + 1

        page.close()
        parse_page.decompose()
        del parse_page
        # Issue#569
        wait()

    return total_list


# Traceback (ZeroDivisionError)
Input: 5
Include Private bookmarks [y/n/o]:
Start Page (default=1):
End Page (default=0, 0 for no limit):
Importing Bookmarks...
Exporting page 1
Source URL: https://www.pixiv.net/bookmark.php?type=user&amp;p=1
Using default DB Path: /mnt/c/PixivUtil2/db.sqlite
No more data
Result:  0 items.
Error at process_bookmark(): (<class 'ZeroDivisionError'>, ZeroDivisionError('float division by zero'), <traceback object at 0x7fa7885a55a0>)
Traceback (most recent call last):
File "PixivUtil2.py", line 2407, in main
np_is_valid, op_is_valid, selection = main_loop(ewd, op_is_valid, selection, np_is_valid, args)
File "PixivUtil2.py", line 2127, in main_loop
menu_download_from_online_user_bookmark(op_is_valid, args)
File "PixivUtil2.py", line 1722, in menu_download_from_online_user_bookmark
process_bookmark(hide, start_page, end_page)
File "PixivUtil2.py", line 1235, in process_bookmark
print("%d/%d\t%f %%" % (i, len(total_list), 100.0 * i / float(len(total_list))))
ZeroDivisionError: float division by zero
press enter to exit.

# Fixed code
def get_image_bookmark(hide, start_page=1, end_page=0, tag="", sorting=None):
    """Get user's image bookmark"""
    total_list = list()
    i = start_page
    offset = 0
    limit = 48
    member_id = __br__._myId

    while True:
        if end_page != 0 and i > end_page:
            print("Page Limit reached: " + str(end_page))
            break

        # https://www.pixiv.net/ajax/user/189816/illusts/bookmarks?tag=&offset=0&limit=48&rest=show
        show = "show"
        if hide:
            show = "hide"

        # # Implement #468 default is desc, only for your own bookmark.
        # not available in current api
        # if sorting in ('asc', 'date_d', 'date'):
        #     url = url + "&order=" + sorting

        if tag is not None and len(tag) > 0:
            tag = PixivHelper.encode_tags(tag)
        offset = limit * (i - 1)
        url = f"https://www.pixiv.net/ajax/user/{member_id}/illusts/bookmarks?tag={tag}&offset={offset}&limit={limit}&rest={show}"

        PixivHelper.print_and_log(
            "info", f"Importing user's bookmarked image from page {i}"
        )
        PixivHelper.print_and_log("info", f"Source URL: {url}")

        page = __br__.open(url)
        page_str = page.read().decode("utf8")
        page.close()

        bookmarks = PixivBookmark.parseImageBookmark(page_str)
        total_list.extend(bookmarks)
        if len(bookmarks) == 0:
            print("No more images.")
            break
        else:
            print(" found " + str(len(bookmarks)) + " images.")

        i = i + 1

        # Issue#569
        wait()

    return total_list