AttributeError: 'NoneType' object has no attribute 'previous_sibling'

filing_doc_text = filing_documents.find('text').extract()

#Get all the thematic breaks. The thematic breaks are in non string form and this process is getting the thematic breaks with header
#and the width of 100%. 
all_thematic_breaks = filing_doc_text.find_all('hr',{'width':'100%'})

#The following code parses the page number from the page and therefore you can print exact number on the pages.

# define a list to house all the page numbers
all_page_numbers = []

for thematic_break in all_thematic_breaks:

    # this would grab the page number tag.
    page_number = thematic_break.parent.parent.previous_sibling.previous_sibling

    # this would grab the page number text
    page_number = page_number.get_text(strip=True)
# store it in the list.

It shows error when i print page_number

Traceback (most recent call last): File "c:\Users\Vanya\Desktop\FINAL\our_code (1).py", line 291, in page_number = thematic_break.parent.parent.previous_sibling.previous_sibling AttributeError: 'NoneType' object has no attribute 'previous_sibling'