Keepa ASIN Screenshots
unknown
python
3 years ago
1.5 kB
11
Indexable
import os
import time
from selenium import webdriver
from selenium.webdriver.chrome.options import Options
from selenium.webdriver.common.by import By
from selenium.webdriver.support.ui import WebDriverWait
from selenium.webdriver.support import expected_conditions as EC
# Define input ASINs and marketplaces
ASINs = ['B07C8XGF63', 'B0061JPJ6O', 'B004UH74DA']
marketplace = 'com' # Change to 'ca' for Amazon Canada or 'com' for Amazon US
# Set up Chrome options
chrome_options = Options()
chrome_options.add_argument('--headless')
chrome_options.add_argument('--disable-gpu')
chrome_options.add_argument('--window-size=1920,1080')
# Set up the driver and the output directory
driver = webdriver.Chrome(options=chrome_options)
output_dir = 'screenshots'
os.makedirs(output_dir, exist_ok=True)
# Iterate over ASINs and take screenshots
for asin in ASINs:
url = f'https://keepa.com/#!product/1-{asin}?domain={marketplace}'
driver.get(url)
# Wait for the chart to load
try:
WebDriverWait(driver, 30).until(
EC.presence_of_element_located((By.CLASS_NAME, 'highcharts-container'))
)
except TimeoutException:
print(f'Timed out waiting for page to load for ASIN: {asin}')
continue
time.sleep(2) # Allow additional time for the chart to fully load
# Save the screenshot
screenshot_path = os.path.join(output_dir, f'{asin}.png')
driver.save_screenshot(screenshot_path)
print(f'Screenshot saved for ASIN: {asin}')
# Close the driver
driver.quit()
Editor is loading...