You can pass lists to the screenshot() method parameters to perform batch operations.
Batching Patterns:
- One filename for multiple inputs: If
save_as is a single string, outputs will be suffixed (e.g., ABC_0.png, ABC_1.png). - Multiple filenames for multiple inputs: If
save_as is a list, it maps 1:1 to the input list. - Multiple resolutions: If
size is a list, it applies different sizes to each item. If the list is shorter than the inputs, the last size is repeated. - Applying CSS to multiple HTML inputs: You can pass a single CSS string to multiple HTML strings, or a list of CSS strings to match a list of HTML strings.
# Create three files from one filename (outputs ABC_0.png, ABC_1.png, ABC_2.png)
hti.screenshot(html_str=['A', 'B', 'C'], save_as='ABC.png')
# Create three files from different filenames (outputs A.png, B.png, C.png)
hti.screenshot(html_str=['A', 'B', 'C'], save_as=['A.png', 'B.png', 'C.png'])
# Multiple screenshots with different sizes
# If not enough sizes are given, the last size in the list will be repeated
hti.screenshot(
html_str=['A', 'B', 'C', 'D'],
size=[(100, 50), (100, 100), (50, 50)]
)
# Apply multiple CSS strings to multiple HTML strings
hti.screenshot(
html_str=['A', 'B'],
css_str=['body {background: red;}', 'body {font-size: 50px;}']
)