diff --git a/app/app.py b/app/app.py index 9715655..63a44cd 100644 --- a/app/app.py +++ b/app/app.py @@ -6,24 +6,22 @@ app = Flask(__name__) +# Create a headless browser instance +options = webdriver.ChromeOptions() +options.add_argument('--headless') +driver = webdriver.Chrome(options=options) + def expand_url(url): try: url = requests.head(url, allow_redirects=True).url - # Create a headless browser instance - options = webdriver.ChromeOptions() - options.add_argument('--headless') - driver = webdriver.Chrome(options=options) - - # Navigate to the URL - driver.get(url) - - # Take a screenshot of the page - driver.save_screenshot('app/assets/screenshot.png') + try: + # Take a screenshot of the page + driver.get(url) + driver.save_screenshot('app/static/screenshots/screenshot.png') + except Exception as e: + return f"Error taking screenshot: {str(e)}" - # Close the browser - driver.quit() - return url except Exception as e: return f"Error expanding URL: {str(e)}"