I'm trying to read in text from a word document, docx and trying to find all the text that has been highlighted in yellow but it gives me an error message
import docx
document = docx.Document(r'C:/Users/devff/Documents/Prac2.docx')
rs = document._element.xpath("//w:r")
WPML_URI = '{http://schemas.openxmlformats.org/wordprocessingml/2006/main}'
tag_rPr = WPML_URI + 'rPr'
tag_highlight = WPML_URI + 'highlight'
tag_val = WPML_URI + 'val'
tag_t = WPML_URI + 't'
for word in rs:
for rPr in word.findall(tag_rPr):
high = rPr.findall(tag_highlight)
for hi in high:
if hi.attribute[tag_val] == 'yellow': ##here is the problem
print(word.find(tag_t).text.encode('utf-8').lower())
ideally it should print out the text thats been highlighted as yellow, but instead it just gives me:
AttributeError: 'CT_Highlight' object has no attribute 'attribute'