Extract Data from Attachments and ZIP Archives
Leave feedback
On this page
Use container extraction to open archive-like formats (ZIP, RAR, TAR), Outlook stores (PST/OST), PDF portfolios, and email attachments, then parse their contents.
Extract and parse attachments
fromgroupdocs.parserimportParserfromgroupdocs.parser.exceptionsimportUnsupportedDocumentFormatExceptionwithParser("./archive.zip")asparser:attachments=parser.get_container()ifattachmentsisNone:print("Container extraction isn't supported for this format.")else:foriteminattachments:print(item.file_path)try:withitem.open_parser()asattachment_parser:reader=attachment_parser.get_text()print(reader.read_to_end()ifreaderisnotNoneelse"No text available.")exceptUnsupportedDocumentFormatException:print("Item format is not supported.")
The following sample file is used in this example: archive.zip
Steps
Instantiate Parser for the container file.
Call get_container() to list ContainerItem entries.
For each item, use open_parser() to create a Parser over the embedded content and reuse standard extraction methods (get_text, get_images, get_metadata, etc.).
Handle unsupported formats with UnsupportedDocumentFormatException.
For working with attachments in complex scenarios (nested containers, load options), see the advanced containers guide.
Was this page helpful?
Any additional feedback you'd like to share with us?
Please tell us how we can improve this page.
Thank you for your feedback!
We value your opinion. Your feedback will help us improve our documentation.
On this page
Analyzing your prompt, please hold on...
An error occurred while retrieving the results. Please refresh the page and try again.