Spaces:
Running
Running
Create app.py
Browse files
app.py
ADDED
@@ -0,0 +1,47 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import gradio as gr
|
2 |
+
import requests
|
3 |
+
from bs4 import BeautifulSoup
|
4 |
+
|
5 |
+
def parse_link(ort):
|
6 |
+
# Konstruiere die vollständige URL
|
7 |
+
url = f"https://vereine-in-deutschland.net/vereine/Bayern/{ort}"
|
8 |
+
|
9 |
+
try:
|
10 |
+
# Senden der Anfrage an die URL
|
11 |
+
response = requests.get(url)
|
12 |
+
response.raise_for_status() # Überprüfen, ob die Anfrage erfolgreich war
|
13 |
+
|
14 |
+
# Parse the HTML content using BeautifulSoup
|
15 |
+
soup = BeautifulSoup(response.content, 'html.parser')
|
16 |
+
|
17 |
+
# Finde den Link mit dem CSS-Selektor
|
18 |
+
link_element = soup.select_one('li.page-item:nth-child(8) > a:nth-child(1)')
|
19 |
+
|
20 |
+
if link_element and 'href' in link_element.attrs:
|
21 |
+
href = link_element['href']
|
22 |
+
# Extrahiere die letzten beiden Zeichen der URL
|
23 |
+
last_two_chars = href[-2:]
|
24 |
+
|
25 |
+
# Konvertiere die letzten beiden Zeichen in einen Integer
|
26 |
+
last_two_chars_int = int(last_two_chars)
|
27 |
+
|
28 |
+
return last_two_chars_int
|
29 |
+
else:
|
30 |
+
return "Link not found"
|
31 |
+
except Exception as e:
|
32 |
+
return str(e)
|
33 |
+
|
34 |
+
# Erstelle die Gradio-Schnittstelle
|
35 |
+
with gr.Blocks() as demo:
|
36 |
+
gr.Markdown("# Vereine in Bayern Parser")
|
37 |
+
ort_input = gr.Textbox(label="Ort", placeholder="Gib den Namen des Ortes ein")
|
38 |
+
output = gr.Number(label="Letzte beiden Zeichen der URL (als Integer)")
|
39 |
+
|
40 |
+
# Button zum Starten der Parsung
|
41 |
+
button = gr.Button("Parse Link")
|
42 |
+
|
43 |
+
# Verbinde den Button mit der Funktion
|
44 |
+
button.click(fn=parse_link, inputs=ort_input, outputs=output)
|
45 |
+
|
46 |
+
# Starte die Gradio-Anwendung
|
47 |
+
demo.launch()
|