mgokg commited on
Commit
f824e57
·
verified ·
1 Parent(s): 2c9db66

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +28 -18
app.py CHANGED
@@ -3,23 +3,34 @@ import requests
3
  from bs4 import BeautifulSoup
4
  from urllib.parse import urljoin
5
 
6
- def parse_links(ort):
7
- # Konstruiere die vollständige URL
8
- initial_url = f"http://specialist-it.de:3000?q={ort}"
9
- # Senden der Anfrage an die initiale URL
10
- response = requests.get(initial_url)
11
- response.raise_for_status() # Überprüfen, ob die Anfrage erfolgreich war
12
- # Parse the HTML content using BeautifulSoup
13
- soup = BeautifulSoup(response.content, 'html.parser')
14
- # Den body-Tag finden
15
- body_tag = soup.find('body')
16
- # Den Text des body-Tags zurückgeben
17
- body_text = body_tag.get_text()
18
- # Den Text ausgeben
19
- print(body_text)
 
 
 
 
 
 
 
 
 
20
 
21
- return body_text
22
-
 
 
23
 
24
  # Erstelle die Gradio-Schnittstelle
25
  with gr.Blocks() as demo:
@@ -31,5 +42,4 @@ with gr.Blocks() as demo:
31
  # Verbinde den Button mit der Funktion
32
  button.click(fn=parse_links, inputs=ort_input, outputs=links_output)
33
 
34
- # Starte die Gradio-Anwendung
35
- demo.launch()
 
3
  from bs4 import BeautifulSoup
4
  from urllib.parse import urljoin
5
 
6
+ def parse_links(ort):
7
+ try:
8
+ # Konstruiere die vollständige URL
9
+ initial_url = "http://spiegel.de"
10
+
11
+ # Senden der Anfrage an die initiale URL
12
+ response = requests.get(initial_url)
13
+ response.raise_for_status() # Überprüfen, ob die Anfrage erfolgreich war
14
+
15
+ # Parse the HTML content using BeautifulSoup
16
+ soup = BeautifulSoup(response.content, 'html.parser')
17
+
18
+ # Den body-Tag finden
19
+ body_tag = soup.find('body')
20
+
21
+ # Den Text des body-Tags zurückgeben
22
+ body_text = body_tag.get_text()
23
+
24
+ # Den Text ausgeben
25
+ print(body_text)
26
+
27
+ # Rückgabe als Dictionary, um es mit gr.JSON kompatibel zu machen
28
+ return {"body_text": body_text}
29
 
30
+ except requests.RequestException as e:
31
+ return {"error": str(e)}
32
+ except Exception as e:
33
+ return {"error": str(e)}
34
 
35
  # Erstelle die Gradio-Schnittstelle
36
  with gr.Blocks() as demo:
 
42
  # Verbinde den Button mit der Funktion
43
  button.click(fn=parse_links, inputs=ort_input, outputs=links_output)
44
 
45
+ #