Currently trying to create a python script that will check a google document for various SEO onpage metrics. To perform my checks I need to be able to split out the H1, H2-H4, text in bold etc & this is a follow-up question to my previous request for help on splitting out the various headings.
The following is how I've been pulling the headings:
def read_paragraph_element(element):
text_run = element.get('textRun')
if not text_run:
return ''
return text_run.get('content')
def read_structural_elements(elements):
for value in elements:
if 'paragraph' in value and value['paragraph']['paragraphStyle']['namedStyleType'] == 'HEADING_2':
elements = value.get('paragraph').get('elements')
for elem in elements:
sub_headings += read_paragraph_element(elem)
When I try to follow a similar logic for bold or italic text, I end up with a blank list:
for value in elements:
if 'paragraph' in value and value['paragraph']['paragraphStyle']['namedStyleType']['paragraphElement']['textStyle'] == 'bold':
elements = value.get('paragraph').get('elements')
for elem in elements:
sub_headings += read_paragraph_element(elem)
I'm pretty new to coding/python and am struggling to see where to go from here.

