Spaces:
Running
Running
Update app.py
Browse files
app.py
CHANGED
@@ -14,12 +14,12 @@ def take_screenshot(url):
|
|
14 |
|
15 |
try:
|
16 |
wd = webdriver.Chrome(options=options)
|
17 |
-
wd.set_window_size(1080, 720) #
|
18 |
wd.get(url)
|
19 |
wd.implicitly_wait(10)
|
20 |
screenshot = wd.get_screenshot_as_png()
|
21 |
except WebDriverException as e:
|
22 |
-
#
|
23 |
return Image.new('RGB', (1, 1))
|
24 |
finally:
|
25 |
if wd:
|
@@ -31,12 +31,12 @@ def take_screenshot(url):
|
|
31 |
def screenshot():
|
32 |
url = request.args.get('url')
|
33 |
if not url:
|
34 |
-
return "URL
|
35 |
|
36 |
-
#
|
37 |
image = take_screenshot(url)
|
38 |
|
39 |
-
#
|
40 |
img_io = BytesIO()
|
41 |
image.save(img_io, 'PNG')
|
42 |
img_io.seek(0)
|
|
|
14 |
|
15 |
try:
|
16 |
wd = webdriver.Chrome(options=options)
|
17 |
+
wd.set_window_size(1080, 720) # ウィンドウサイズの調整
|
18 |
wd.get(url)
|
19 |
wd.implicitly_wait(10)
|
20 |
screenshot = wd.get_screenshot_as_png()
|
21 |
except WebDriverException as e:
|
22 |
+
# エラーが発生した場合は、プレースホルダーとして空の画像を返す
|
23 |
return Image.new('RGB', (1, 1))
|
24 |
finally:
|
25 |
if wd:
|
|
|
31 |
def screenshot():
|
32 |
url = request.args.get('url')
|
33 |
if not url:
|
34 |
+
return "URLパラメーターが必要です。", 400
|
35 |
|
36 |
+
# 指定されたURLのスクリーンショットを撮影
|
37 |
image = take_screenshot(url)
|
38 |
|
39 |
+
# スクリーンショットをメモリ上に保存し、レスポンスとして返す
|
40 |
img_io = BytesIO()
|
41 |
image.save(img_io, 'PNG')
|
42 |
img_io.seek(0)
|