soiz commited on
Commit
d326685
·
verified ·
1 Parent(s): 602cdfd

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +5 -5
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) # Adjust the window size here
18
  wd.get(url)
19
  wd.implicitly_wait(10)
20
  screenshot = wd.get_screenshot_as_png()
21
  except WebDriverException as e:
22
- # If there's an error, return a blank image as a placeholder
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 parameter is required.", 400
35
 
36
- # Take the screenshot of the provided URL
37
  image = take_screenshot(url)
38
 
39
- # Save the screenshot to an in-memory file and return as response
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)