I find the document http://python-docx.readthedocs.io/en/latest/dev/analysis/features/header.html .But it said that it is under development. So I wonder is there anyway that I can read the header or footer of a docx?
When you parse a docx file with docx.Document(docx_file_path), you would got a Document object, like this:
doc = docx.Document(docx_file)
and then you can get the xmls of headers or footers in the docxfile by:
headers = [x.blob.decode() for x in doc.part.package.parts if x.partname.find('header')>0]
then you could use some moudle like lxml to parse the xml texts.
Header and footer support will be released with v0.8.8 in the next day or two. Until then a working version is available on the spike-header branch.
Most helpful comment
When you parse a docx file with docx.Document(docx_file_path), you would got a Document object, like this:
doc = docx.Document(docx_file)and then you can get the xmls of headers or footers in the docxfile by:
headers = [x.blob.decode() for x in doc.part.package.parts if x.partname.find('header')>0]then you could use some moudle like lxml to parse the xml texts.