Update app.py
Browse files
app.py
CHANGED
@@ -1,35 +1,35 @@
|
|
1 |
-
import gradio as gr
|
2 |
from selenium import webdriver
|
3 |
-
from selenium.
|
4 |
-
from
|
5 |
-
from
|
|
|
|
|
|
|
6 |
|
7 |
-
|
8 |
-
|
9 |
-
|
10 |
-
|
11 |
-
|
12 |
|
13 |
-
|
14 |
-
|
15 |
-
wd.set_window_size(1080, 720) # Adjust the window size here
|
16 |
-
wd.get(url)
|
17 |
-
wd.implicitly_wait(30)
|
18 |
-
screenshot = wd.get_screenshot_as_png()
|
19 |
-
except WebDriverException as e:
|
20 |
-
return Image.new('RGB', (1, 1))
|
21 |
-
finally:
|
22 |
-
if wd:
|
23 |
-
wd.quit()
|
24 |
|
25 |
-
|
|
|
|
|
26 |
|
27 |
-
|
28 |
-
|
29 |
-
inputs=gr.Textbox(label="Website URL", value="https://kargaranamir.github.io"),
|
30 |
-
outputs=gr.Image(type="pil", label="Screenshot", height=360, width=540), # Adjust the image size here
|
31 |
-
title="Website Screenshot",
|
32 |
-
description="Take a screenshot of a website."
|
33 |
-
)
|
34 |
|
35 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
from selenium import webdriver
|
2 |
+
from selenium.webdriver.chrome.service import Service
|
3 |
+
from webdriver_manager.chrome import ChromeDriverManager
|
4 |
+
from selenium.webdriver.chrome.options import Options
|
5 |
+
from selenium.webdriver.common.by import By
|
6 |
+
from selenium.webdriver.support.ui import WebDriverWait
|
7 |
+
from selenium.webdriver.support import expected_conditions as EC
|
8 |
|
9 |
+
# Set Chrome to run in headless mode to save memory
|
10 |
+
chrome_options = Options()
|
11 |
+
chrome_options.add_argument("--headless") # Headless mode
|
12 |
+
chrome_options.add_argument("--no-sandbox") # Necessary for running in some environments
|
13 |
+
chrome_options.add_argument("--disable-dev-shm-usage") # Overcome limited resource problems
|
14 |
|
15 |
+
# Initialize the Chrome WebDriver
|
16 |
+
driver = webdriver.Chrome(service=Service(ChromeDriverManager().install()), options=chrome_options)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
17 |
|
18 |
+
# Go to the provided URL
|
19 |
+
url = "https://genyoutube.online/url=https://www.youtube.com/watch?v=-2RAq5o5pwc&list=RD-2RAq5o5pwc&start_radio=1"
|
20 |
+
driver.get(url)
|
21 |
|
22 |
+
# Print the page title to verify success
|
23 |
+
print(driver.title)
|
|
|
|
|
|
|
|
|
|
|
24 |
|
25 |
+
# Use WebDriverWait to wait for the element to be present
|
26 |
+
try:
|
27 |
+
my_tab_content = WebDriverWait(driver, 10).until(
|
28 |
+
EC.presence_of_element_located((By.ID, "myTabContent"))
|
29 |
+
)
|
30 |
+
print(my_tab_content.text) # Print the text content
|
31 |
+
except Exception as e:
|
32 |
+
print("Error locating the element:", e)
|
33 |
+
|
34 |
+
# Close the browser session
|
35 |
+
driver.quit()
|