File size: 993 Bytes
12e023b
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
from html2image import Html2Image
import os

# Define the types array to process
types = ['zhihu', 'paper']  # Add all types you need to process here

# Initialize Html2Image object
hti = Html2Image()
hti.browser.use_new_headless = None  # Keep default settings

for type_txt in types:
    # Ensure png directory exists
    output_dir = os.path.join('png', f"sample_process_{type_txt}")
    if not os.path.exists(output_dir):
        os.makedirs(output_dir)
    
    # Set output path for current type
    hti.output_path = output_dir
    
    # Loop to generate screenshots
    for i in range(1, 65):
        # Get HTML file path
        html_path = os.path.join('html', f"sample_process_{type_txt}", f'visualization_step_{i}.html')
        
        # Generate and save screenshot
        hti.screenshot(
            url=html_path,
            save_as=f'visualization_step_{i}.png',
            size=(1200, 500) if type_txt == 'zhihu' else (1200, 800)
        )