Spaces:
Running
Running
Update app.py
Browse files
app.py
CHANGED
@@ -4,7 +4,7 @@ import os
|
|
4 |
import json
|
5 |
import google.generativeai as genai
|
6 |
from bs4 import BeautifulSoup
|
7 |
-
|
8 |
|
9 |
# Load environment variables
|
10 |
genai.configure(api_key=os.environ["geminiapikey"])
|
@@ -27,27 +27,20 @@ def google_search(search_term, **kwargs):
|
|
27 |
return res
|
28 |
|
29 |
def get_impressum_text(search_term):
|
30 |
-
try:
|
31 |
-
search_results = google_search(search_term)
|
32 |
|
33 |
-
|
34 |
-
for item in search_results['items']:
|
35 |
-
link = item['link']
|
36 |
-
try:
|
37 |
-
response = requests.get(link, timeout=5) # Timeout hinzugefügt für Fehlerbehandlung
|
38 |
-
response.raise_for_status() # Wirft eine Exception, wenn der Statuscode nicht 200 ist
|
39 |
-
soup = BeautifulSoup(response.content, 'html.parser')
|
40 |
|
41 |
-
|
|
|
|
|
|
|
|
|
|
|
42 |
|
43 |
-
|
44 |
-
return impressum_div.text.strip()
|
45 |
|
46 |
-
|
47 |
-
print(f"Fehler beim Abrufen der URL {link}: {e}")
|
48 |
-
continue # Weiter mit dem nächsten Suchergebnis
|
49 |
|
50 |
-
return None # Kein Impressum gefunden
|
51 |
|
52 |
|
53 |
def websearch(prompt):
|
|
|
4 |
import json
|
5 |
import google.generativeai as genai
|
6 |
from bs4 import BeautifulSoup
|
7 |
+
from googleapiclient.discovery import build
|
8 |
|
9 |
# Load environment variables
|
10 |
genai.configure(api_key=os.environ["geminiapikey"])
|
|
|
27 |
return res
|
28 |
|
29 |
def get_impressum_text(search_term):
|
|
|
|
|
30 |
|
31 |
+
search_results = google_search(search_term)
|
|
|
|
|
|
|
|
|
|
|
|
|
32 |
|
33 |
+
if 'items' in search_results:
|
34 |
+
for item in search_results['items']:
|
35 |
+
link = item['link']
|
36 |
+
response = requests.get(link, timeout=5) # Timeout hinzugefügt für Fehlerbehandlung
|
37 |
+
response.raise_for_status() # Wirft eine Exception, wenn der Statuscode nicht 200 ist
|
38 |
+
soup = BeautifulSoup(response.content, 'html.parser')
|
39 |
|
40 |
+
impressum_div = soup.find('div', class_='MjjYud')
|
|
|
41 |
|
42 |
+
return impressum_div.text.strip()
|
|
|
|
|
43 |
|
|
|
44 |
|
45 |
|
46 |
def websearch(prompt):
|