Spaces:
Running
Running
Update app.py
Browse files
app.py
CHANGED
@@ -21,8 +21,6 @@ def download_noto_sans_cjk():
|
|
21 |
download_noto_sans_cjk()
|
22 |
|
23 |
|
24 |
-
|
25 |
-
|
26 |
from flask import Flask, request, send_file
|
27 |
from selenium import webdriver
|
28 |
from selenium.common.exceptions import WebDriverException
|
@@ -39,12 +37,12 @@ def take_screenshot(url):
|
|
39 |
|
40 |
try:
|
41 |
wd = webdriver.Chrome(options=options)
|
42 |
-
wd.set_window_size(1080, 720) #
|
43 |
wd.get(url)
|
44 |
wd.implicitly_wait(10)
|
45 |
screenshot = wd.get_screenshot_as_png()
|
46 |
except WebDriverException as e:
|
47 |
-
#
|
48 |
return Image.new('RGB', (1, 1))
|
49 |
finally:
|
50 |
if wd:
|
@@ -56,12 +54,12 @@ def take_screenshot(url):
|
|
56 |
def screenshot():
|
57 |
url = request.args.get('url')
|
58 |
if not url:
|
59 |
-
return "URL
|
60 |
|
61 |
-
#
|
62 |
image = take_screenshot(url)
|
63 |
|
64 |
-
#
|
65 |
img_io = BytesIO()
|
66 |
image.save(img_io, 'PNG')
|
67 |
img_io.seek(0)
|
|
|
21 |
download_noto_sans_cjk()
|
22 |
|
23 |
|
|
|
|
|
24 |
from flask import Flask, request, send_file
|
25 |
from selenium import webdriver
|
26 |
from selenium.common.exceptions import WebDriverException
|
|
|
37 |
|
38 |
try:
|
39 |
wd = webdriver.Chrome(options=options)
|
40 |
+
wd.set_window_size(1080, 720) # Adjust the window size here
|
41 |
wd.get(url)
|
42 |
wd.implicitly_wait(10)
|
43 |
screenshot = wd.get_screenshot_as_png()
|
44 |
except WebDriverException as e:
|
45 |
+
# If there's an error, return a blank image as a placeholder
|
46 |
return Image.new('RGB', (1, 1))
|
47 |
finally:
|
48 |
if wd:
|
|
|
54 |
def screenshot():
|
55 |
url = request.args.get('url')
|
56 |
if not url:
|
57 |
+
return "URL parameter is required.", 400
|
58 |
|
59 |
+
# Take the screenshot of the provided URL
|
60 |
image = take_screenshot(url)
|
61 |
|
62 |
+
# Save the screenshot to an in-memory file and return as response
|
63 |
img_io = BytesIO()
|
64 |
image.save(img_io, 'PNG')
|
65 |
img_io.seek(0)
|