import zipfile import xml.etree.ElementTree as ET def get_docx_text(path): try: doc = zipfile.ZipFile(path) xml_content = doc.read('word/document.xml') root = ET.fromstring(xml_content) # Word XML namespaces ns = {'w': 'http://schemas.openxmlformats.org/wordprocessingml/2006/main'} paragraphs = [] for paragraph in root.iter('{http://schemas.openxmlformats.org/wordprocessingml/2006/main}p'): texts = [node.text for node in paragraph.iter('{http://schemas.openxmlformats.org/wordprocessingml/2006/main}t') if node.text] if texts: paragraphs.append("".join(texts)) return "\n".join(paragraphs) except Exception as e: return f"Error reading {path}: {e}" if __name__ == "__main__": text = get_docx_text(r"c:\Users\lanfr144\Documents\DOPRO1\Antigravity\todo.docx") print(text)