All checks were successful
Sync To /home/ubuntu/gfps / sync (push) Successful in 2s
Change-Id: I71e676b997159a141ca07d16f82a73b45f4b2410
46 lines
1.4 KiB
Python
46 lines
1.4 KiB
Python
import os
|
|
import email
|
|
from email import policy
|
|
import re
|
|
from bs4 import BeautifulSoup
|
|
|
|
def analyze_file(filepath):
|
|
print(f"--- Analyzing {filepath} ---")
|
|
with open(filepath, 'rb') as f:
|
|
msg = email.message_from_bytes(f.read(), policy=policy.default)
|
|
|
|
html_content = ""
|
|
images = []
|
|
|
|
if msg.is_multipart():
|
|
for part in msg.walk():
|
|
ctype = part.get_content_type()
|
|
if ctype == 'text/html':
|
|
html_content = part.get_payload(decode=True).decode(part.get_content_charset() or 'utf-8', errors='ignore')
|
|
elif ctype.startswith('image/'):
|
|
cloc = part.get("Content-Location")
|
|
cid = part.get("Content-ID")
|
|
images.append({"type": ctype, "location": cloc, "id": cid})
|
|
|
|
if not html_content:
|
|
print("No HTML found.")
|
|
return
|
|
|
|
soup = BeautifulSoup(html_content, 'html.parser')
|
|
wiki_content = soup.find(class_='wiki-content')
|
|
if wiki_content:
|
|
print("Found .wiki-content!")
|
|
else:
|
|
print("No .wiki-content found, using full body.")
|
|
|
|
img_tags = soup.find_all('img')
|
|
print(f"Found {len(img_tags)} img tags.")
|
|
for img in img_tags[:5]:
|
|
print(f" img src: {img.get('src')}")
|
|
|
|
print(f"Images in MHT: {len(images)}")
|
|
for img in images[:5]:
|
|
print(f" {img}")
|
|
|
|
analyze_file("1. Google test group.doc")
|