mgokg commited on
Commit
9c0c9be
·
verified ·
1 Parent(s): f9e84b8

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +25 -16
app.py CHANGED
@@ -4,30 +4,39 @@ from selenium.common.exceptions import WebDriverException
4
  from selenium.webdriver.common.by import By
5
 
6
 
7
- resp=""
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
- wd.implicitly_wait(3)
17
- #element=wd.find_element(By.TAG_NAME, "body")
18
- #button_send = driver.find_element(By.ID, "L2AGLb").click()
19
- element = wd.find_element(By.TAG_NAME, "body")
20
- body_html = element.get_attribute("outerHTML")
21
- #return body_html
 
 
 
 
 
 
 
 
 
 
22
 
23
- return element.text
24
 
25
  iface = gr.Interface(
26
- fn=take_screenshot,
27
- inputs=gr.Textbox(label="Website URL", value="https://spiegel.de"),
 
 
 
 
28
  outputs=gr.Textbox(),
29
  title="Website Screenshot",
30
- description="Take a screenshot of a website."
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()