Spaces:
Sleeping
Sleeping
arxivgpt kim
commited on
Update app.py
Browse files
app.py
CHANGED
@@ -1,10 +1,12 @@
|
|
1 |
import gradio as gr
|
2 |
from selenium import webdriver
|
3 |
from selenium.common.exceptions import WebDriverException
|
|
|
|
|
4 |
from PIL import Image
|
5 |
from io import BytesIO
|
6 |
|
7 |
-
def take_screenshot(url):
|
8 |
options = webdriver.ChromeOptions()
|
9 |
options.add_argument('--headless')
|
10 |
options.add_argument('--no-sandbox')
|
@@ -12,10 +14,19 @@ def take_screenshot(url):
|
|
12 |
|
13 |
wd = None
|
14 |
try:
|
15 |
-
|
16 |
-
wd.
|
17 |
wd.get(url)
|
18 |
wd.implicitly_wait(10)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
19 |
screenshot = wd.get_screenshot_as_png()
|
20 |
except WebDriverException as e:
|
21 |
return Image.new('RGB', (1, 1))
|
@@ -27,10 +38,13 @@ def take_screenshot(url):
|
|
27 |
|
28 |
iface = gr.Interface(
|
29 |
fn=take_screenshot,
|
30 |
-
inputs=
|
31 |
-
|
|
|
|
|
|
|
32 |
title="Website Screenshot",
|
33 |
-
description="Take a screenshot of a website.",
|
34 |
)
|
35 |
|
36 |
iface.launch()
|
|
|
1 |
import gradio as gr
|
2 |
from selenium import webdriver
|
3 |
from selenium.common.exceptions import WebDriverException
|
4 |
+
from selenium.webdriver.chrome.service import Service
|
5 |
+
from webdriver_manager.chrome import ChromeDriverManager
|
6 |
from PIL import Image
|
7 |
from io import BytesIO
|
8 |
|
9 |
+
def take_screenshot(url, capture_type):
|
10 |
options = webdriver.ChromeOptions()
|
11 |
options.add_argument('--headless')
|
12 |
options.add_argument('--no-sandbox')
|
|
|
14 |
|
15 |
wd = None
|
16 |
try:
|
17 |
+
service = Service(ChromeDriverManager().install())
|
18 |
+
wd = webdriver.Chrome(service=service, options=options)
|
19 |
wd.get(url)
|
20 |
wd.implicitly_wait(10)
|
21 |
+
|
22 |
+
if capture_type == "전체 페이지":
|
23 |
+
# 전체 페이지 높이와 너비를 가져옵니다.
|
24 |
+
total_width = wd.execute_script("return document.body.offsetWidth")
|
25 |
+
total_height = wd.execute_script("return document.body.parentNode.scrollHeight")
|
26 |
+
wd.set_window_size(total_width, total_height) # 윈도우 크기를 전체 페이지 크기로 조정합니다.
|
27 |
+
else:
|
28 |
+
wd.set_window_size(1024, 768) # 기본 크기
|
29 |
+
|
30 |
screenshot = wd.get_screenshot_as_png()
|
31 |
except WebDriverException as e:
|
32 |
return Image.new('RGB', (1, 1))
|
|
|
38 |
|
39 |
iface = gr.Interface(
|
40 |
fn=take_screenshot,
|
41 |
+
inputs=[
|
42 |
+
gr.inputs.Textbox(label="Website URL", default="https://korating.com"),
|
43 |
+
gr.inputs.Radio(choices=["기본 크기", "전체 페이지"], label="캡처 유형 선택")
|
44 |
+
],
|
45 |
+
outputs=gr.Image(type="pil", tool="editor"),
|
46 |
title="Website Screenshot",
|
47 |
+
description="Take a screenshot of a website. Choose '전체 페이지' to capture the full page.",
|
48 |
)
|
49 |
|
50 |
iface.launch()
|