Update app.py
Browse files
app.py
CHANGED
@@ -4,30 +4,39 @@ from selenium.common.exceptions import WebDriverException
|
|
4 |
from selenium.webdriver.common.by import By
|
5 |
|
6 |
|
7 |
-
|
8 |
-
def take_screenshot(url):
|
9 |
options = webdriver.ChromeOptions()
|
10 |
options.add_argument('--headless')
|
11 |
-
#options.add_argument('--no-sandbox')
|
12 |
-
#options.add_argument('--disable-dev-shm-usage')
|
13 |
wd = webdriver.Chrome(options=options)
|
14 |
-
wd.get(url)
|
15 |
|
16 |
-
|
17 |
-
|
18 |
-
|
19 |
-
|
20 |
-
|
21 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
22 |
|
23 |
-
return element.text
|
24 |
|
25 |
iface = gr.Interface(
|
26 |
-
fn=
|
27 |
-
inputs=
|
|
|
|
|
|
|
|
|
28 |
outputs=gr.Textbox(),
|
29 |
title="Website Screenshot",
|
30 |
-
description="Take
|
31 |
)
|
32 |
|
33 |
-
iface.launch()
|
|
|
4 |
from selenium.webdriver.common.by import By
|
5 |
|
6 |
|
7 |
+
def take_screenshots(start, end, step):
|
|
|
8 |
options = webdriver.ChromeOptions()
|
9 |
options.add_argument('--headless')
|
|
|
|
|
10 |
wd = webdriver.Chrome(options=options)
|
|
|
11 |
|
12 |
+
results = []
|
13 |
+
|
14 |
+
for i in range(start, end + 1, step):
|
15 |
+
url = f"https://www.google.com/search?q=vereine+bamberg&start={i}"
|
16 |
+
wd.get(url)
|
17 |
+
wd.implicitly_wait(3)
|
18 |
+
|
19 |
+
try:
|
20 |
+
element = wd.find_element(By.TAG_NAME, "body")
|
21 |
+
body_text = element.text
|
22 |
+
results.append(body_text)
|
23 |
+
except Exception as e:
|
24 |
+
print(f"Error fetching data from {url}: {e}")
|
25 |
+
|
26 |
+
wd.quit()
|
27 |
+
return "\n".join(results)
|
28 |
|
|
|
29 |
|
30 |
iface = gr.Interface(
|
31 |
+
fn=take_screenshots,
|
32 |
+
inputs=[
|
33 |
+
gr.Number(label="Start Index", value=10),
|
34 |
+
gr.Number(label="End Index", value=100),
|
35 |
+
gr.Number(label="Step Size", value=10)
|
36 |
+
],
|
37 |
outputs=gr.Textbox(),
|
38 |
title="Website Screenshot",
|
39 |
+
description="Take screenshots of websites in specified range and step size."
|
40 |
)
|
41 |
|
42 |
+
iface.launch()
|