Paste exactly what you posted into chatgpt. Added I wanted a python script.
import re
import os
from bs4 import BeautifulSoup
import base64
# Read the HTML content from the file
file_path = 'path/to/your/file.html' # Update this with the path to your HTML file
with open(file_path, 'r', encoding='utf-8') as file:
html_content = file.read()
# Parse the HTML content
soup = BeautifulSoup(html_content, 'html.parser')
# Find all elements that contain the image data
image_elements = soup.find_all('v:shape', {'o:gfxdata': True})
# Create a directory to save the extracted images
output_dir = 'extracted_images'
os.makedirs(output_dir, exist_ok=True)
# Loop through each image element and extract the image data
for index, element in enumerate(image_elements):
# Extract the base64 image data
gfxdata = element.get('o:gfxdata')
# Decode the base64 data
image_data = base64.b64decode(gfxdata)
# Determine the image format (assuming PNG for this example)
image_filename = os.path.join(output_dir, f'image_{index + 1}.png')
# Save the image to a file
with open(image_filename, 'wb') as image_file:
image_file.write(image_data)
print(f'Saved {image_filename}')