Update app.py
Browse files
app.py
CHANGED
@@ -1,25 +1,24 @@
|
|
1 |
import gradio as gr
|
2 |
from selenium import webdriver
|
3 |
-
from selenium.common.exceptions import WebDriverException
|
4 |
from selenium.webdriver.common.by import By
|
5 |
from selenium.webdriver.common.keys import Keys
|
6 |
-
from selenium.webdriver.
|
7 |
-
from webdriver_manager.
|
8 |
from PIL import Image
|
9 |
from io import BytesIO
|
10 |
import time
|
11 |
|
12 |
def take_screenshot_and_login(url, email, password):
|
13 |
-
options = webdriver.
|
14 |
options.add_argument('--headless')
|
15 |
options.add_argument('--no-sandbox')
|
16 |
options.add_argument('--disable-dev-shm-usage')
|
17 |
|
18 |
wd = None
|
19 |
try:
|
20 |
-
# Use
|
21 |
-
service =
|
22 |
-
wd = webdriver.
|
23 |
|
24 |
wd.set_window_size(1080, 720)
|
25 |
wd.get(url)
|
@@ -37,8 +36,8 @@ def take_screenshot_and_login(url, email, password):
|
|
37 |
|
38 |
# Take a screenshot
|
39 |
screenshot = wd.get_screenshot_as_png()
|
40 |
-
except
|
41 |
-
print(f"
|
42 |
return Image.new('RGB', (1080, 720), color='white')
|
43 |
finally:
|
44 |
if wd:
|
|
|
1 |
import gradio as gr
|
2 |
from selenium import webdriver
|
|
|
3 |
from selenium.webdriver.common.by import By
|
4 |
from selenium.webdriver.common.keys import Keys
|
5 |
+
from selenium.webdriver.firefox.service import Service as FirefoxService
|
6 |
+
from webdriver_manager.firefox import GeckoDriverManager
|
7 |
from PIL import Image
|
8 |
from io import BytesIO
|
9 |
import time
|
10 |
|
11 |
def take_screenshot_and_login(url, email, password):
|
12 |
+
options = webdriver.FirefoxOptions()
|
13 |
options.add_argument('--headless')
|
14 |
options.add_argument('--no-sandbox')
|
15 |
options.add_argument('--disable-dev-shm-usage')
|
16 |
|
17 |
wd = None
|
18 |
try:
|
19 |
+
# Use GeckoDriverManager to automatically manage the Geckodriver executable
|
20 |
+
service = FirefoxService(GeckoDriverManager().install())
|
21 |
+
wd = webdriver.Firefox(service=service, options=options)
|
22 |
|
23 |
wd.set_window_size(1080, 720)
|
24 |
wd.get(url)
|
|
|
36 |
|
37 |
# Take a screenshot
|
38 |
screenshot = wd.get_screenshot_as_png()
|
39 |
+
except Exception as e:
|
40 |
+
print(f"Exception occurred: {e}")
|
41 |
return Image.new('RGB', (1080, 720), color='white')
|
42 |
finally:
|
43 |
if wd:
|