mgokg commited on
Commit
5879af1
·
verified ·
1 Parent(s): 0c170dc

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +28 -25
app.py CHANGED
@@ -3,32 +3,38 @@ from selenium import webdriver
3
  from selenium.common.exceptions import WebDriverException
4
  from selenium.webdriver.common.by import By
5
  from gradio_client import Client
 
 
 
6
 
7
-
8
- def take_screenshots(ort, start, end, step):
9
  options = webdriver.ChromeOptions()
10
  options.add_argument('--headless')
11
  wd = webdriver.Chrome(options=options)
12
-
13
- results = []
14
-
15
- for i in range(start, end + 1, step):
16
- #url = f"https://www.google.com/search?q=vereine+{ort}&start={i}"
17
- url =f"https://www.google.com/search?q=vereine+{ort}&udm=1&start={i}"
18
-
19
 
20
-
21
- #url = f"https://www.google.com/search&start={i}?client=ubuntu-sn&hs=IfI&sca_esv=87428cc8fad3a684&channel=fs&sxsrf=ADLYWILS7FFOYHO5lGqnnazhj3oUCD5brg:1732777961189&q=vereine+coburg&udm=1&fbs=AEQNm0A6bwEop21ehxKWq5cj-cHa02QUie7apaStVTrDAEoT1GgxBwUH1JWFUZ5PObPyzN6ZUsA_o5eBQ6q3XCohkYS3xwvahKNlHLvb7ik7d2FuZj0TOof95P-zQ_8CiAOTe_v8hfAibflUmrJL4FWa_eOcMb26glFo9Yxba4fVczAb7MDRkvPj2OyJbBpnWvmNz0EzxJ0sKYEcdGCvmX8E2KcIAu46WQ&sa=X&ved=2ahUKEwjLsef2vP6JAxXH1QIHHQD_OwQQs6gLegQIFRAB&biw=1558&bih=753&dpr=1"
22
- wd.get(url)
23
- wd.implicitly_wait(3)
24
-
25
- try:
26
- element = wd.find_element(By.TAG_NAME, "body")
27
- body_text = element.text
28
- results.append(body_text)
29
- except Exception as e:
30
- print(f"Error fetching data from {url}: {e}")
 
 
31
 
 
 
 
32
  wd.quit()
33
  #erg ="\n".join(results)
34
  #return erg
@@ -52,13 +58,10 @@ iface = gr.Interface(
52
  fn=take_screenshots,
53
  inputs=[
54
  gr.Textbox(label="Ort", value=""),
55
- gr.Number(label="Start Index", value=10),
56
- gr.Number(label="Anzahl Vereine", value=100),
57
- gr.Number(label="Step", value=10),
58
  ],
59
  outputs=gr.Textbox(),
60
- title="Website Screenshot",
61
- description="Take screenshots of websites in specified range and step size for a given location."
62
  )
63
 
64
  iface.launch()
 
3
  from selenium.common.exceptions import WebDriverException
4
  from selenium.webdriver.common.by import By
5
  from gradio_client import Client
6
+ from selenium.webdriver.support.wait import WebDriverWait
7
+ from selenium.webdriver.support import expected_conditions as EC
8
+ from selenium.webdriver.chrome.options import Options
9
 
10
+ def selenium(message):
 
11
  options = webdriver.ChromeOptions()
12
  options.add_argument('--headless')
13
  wd = webdriver.Chrome(options=options)
14
+ text_input = WebDriverWait(driver, 15).until(
15
+ EC.presence_of_element_located((By.XPATH, '/html/body/main/div/div/div[2]/div[1]/div/div[3]/div/div/div[2]/div[2]/div/div/span/div/div/div/div[1]/textarea'))
16
+ )
17
+ text_input.send_keys(prompt)
18
+ button_send = driver.find_element(By.XPATH, '/html/body/main/div/div/div[2]/div[1]/div/div[3]/div/div/div[2]/div[2]/div/div/span/div/div/div/div[3]/button').click()
19
+ time.sleep(5)
 
20
 
21
+ txtelements = driver.find_elements(By.XPATH, '/html/body/main/div/div/div[2]/div[1]/div/div[3]/div/div[1]/div/div[2]/div/div[1]/div[2]/div[2]/div[2]')
22
+ #text_el = txtelements.text
23
+ time.sleep(5)
24
+ txtcode = ""
25
+ #with open("datei.txt", "w") as f:
26
+ #f.write(code)
27
+ #response_code = {"result": code}
28
+ #json.dump(response_code, open('code.json', 'w'), indent=4, sort_keys=True)
29
+ for e in txtelements:
30
+ txtcode += e.text
31
+ #response_txt = {"result": txtcode}
32
+ #print(code)
33
+ print(txtcode)
34
 
35
+ #json.dump(response_txt, open('text.json', 'w'), indent=4, sort_keys=True)
36
+ #json.dump(response_code, open('code.json', 'w'), indent=4, sort_keys=True)
37
+ return txtcode
38
  wd.quit()
39
  #erg ="\n".join(results)
40
  #return erg
 
58
  fn=take_screenshots,
59
  inputs=[
60
  gr.Textbox(label="Ort", value=""),
 
 
 
61
  ],
62
  outputs=gr.Textbox(),
63
+ title="perplexity.ai",
64
+ description="get answer from perplexity"
65
  )
66
 
67
  iface.launch()