This script performs well for me:
from docx import Document
def extract_highlighted_text(docx_path):
doc = Document(docx_path)
highlighted_texts = []
for para in doc.paragraphs:
for run in para.runs:
if run.font.highlight_color is not None:
highlighted_texts.append(run.text)
return highlighted_texts
docx_file = "text.docx"
highlighted_texts = extract_highlighted_text(docx_file)
print("Highlighted Texts:")
for text in highlighted_texts:
print(text)
Result: