File size: 1,208 Bytes
9305c51
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
32
33
34
35
36
37
38
39
import os
from selenium import webdriver
from selenium.webdriver.chrome.options import Options
from PIL import Image
from ascii_magic import from_image_file, to_terminal

def capture_screenshot(url, output_path='screenshot.png'):
    # Set up headless Chrome
    chrome_options = Options()
    chrome_options.add_argument('--headless')
    chrome_options.add_argument('--disable-gpu')
    chrome_options.add_argument('--window-size=1920,1080')

    # Initialize WebDriver
    driver = webdriver.Chrome(options=chrome_options)
    driver.get(url)

    # Save screenshot
    driver.save_screenshot(output_path)
    driver.quit()

def convert_to_ascii(image_path):
    # Convert image to ASCII art
    output = from_image_file(image_path, columns=100, char='#')
    to_terminal(output)

if __name__ == '__main__':
    url = input("Enter the website URL (e.g., https://example.com): ").strip()
    screenshot_file = 'screenshot.png'

    print(f"\nCapturing screenshot of {url}...")
    capture_screenshot(url, screenshot_file)

    print("\nConverting screenshot to ASCII art:\n")
    convert_to_ascii(screenshot_file)

    # Optional: Remove the screenshot file after conversion
    os.remove(screenshot_file)