import gzip, io data = open('pubmed26n1546.xml.gz', 'rb').read() print(f'File size: {len(data)}') try: decomp = gzip.decompress(data) print(f'Valid gzip! Decompressed: {len(decomp)} bytes') from lxml import etree root = etree.parse(io.BytesIO(decomp)).getroot() articles = root.findall('.//PubmedArticle') deletes = root.findall('.//DeleteCitation') print(f'PubmedArticle: {len(articles)}, DeleteCitation: {len(deletes)}') except Exception as e: print(f'Corrupted: {e}')