add googleMaps scraping and openAI playground project
This commit is contained in:
66
scrape_GoogleMaps/scrape.py
Normal file
66
scrape_GoogleMaps/scrape.py
Normal file
@@ -0,0 +1,66 @@
|
||||
import requests
|
||||
import pandas as pd
|
||||
|
||||
# Google API Key (ersetzen durch deinen Schlüssel)
|
||||
API_KEY = 'ENTER HERE'
|
||||
|
||||
# Base URL für die Google Places API
|
||||
BASE_URL = "https://maps.googleapis.com/maps/api/place/nearbysearch/json"
|
||||
|
||||
def search_places(query, location, radius=5000):
|
||||
"""
|
||||
Sucht Orte basierend auf Query und Standort.
|
||||
|
||||
:param query: Suchbegriff (z. B. 'Therapeuten')
|
||||
:param location: Standort als 'latitude,longitude'
|
||||
:param radius: Suchradius in Metern (Standard: 5000)
|
||||
:return: Liste von Orten
|
||||
"""
|
||||
params = {
|
||||
'key': API_KEY,
|
||||
'keyword': query,
|
||||
'location': location,
|
||||
'radius': radius
|
||||
}
|
||||
response = requests.get(BASE_URL, params=params, verify=False)
|
||||
if response.status_code == 200:
|
||||
return response.json().get('results', [])
|
||||
else:
|
||||
print(f"Error: {response.status_code}, {response.text}")
|
||||
return []
|
||||
|
||||
def save_to_csv(data, filename):
|
||||
"""
|
||||
Speichert die Daten in einer CSV-Datei.
|
||||
|
||||
:param data: Liste von Orten
|
||||
:param filename: Name der CSV-Datei
|
||||
"""
|
||||
df = pd.DataFrame(data)
|
||||
df.to_csv(filename, index=False)
|
||||
print(f"Datei gespeichert: {filename}")
|
||||
|
||||
def main():
|
||||
query = input("Gib den Suchbegriff ein (z. B. 'Therapeuten'): ")
|
||||
location = input("Gib den Standort ein (z. B. '52.5200,13.4050' für Berlin): ")
|
||||
radius = int(input("Gib den Suchradius in Metern ein (z. B. 5000): "))
|
||||
|
||||
places = search_places(query, location, radius)
|
||||
|
||||
if places:
|
||||
formatted_data = [
|
||||
{
|
||||
'Name': place.get('name'),
|
||||
'Adresse': place.get('vicinity'),
|
||||
'Bewertung': place.get('rating', 'N/A'),
|
||||
'Anzahl Bewertungen': place.get('user_ratings_total', 'N/A'),
|
||||
'Typ': ', '.join(place.get('types', []))
|
||||
}
|
||||
for place in places
|
||||
]
|
||||
save_to_csv(formatted_data, 'places.csv')
|
||||
else:
|
||||
print("Keine Ergebnisse gefunden.")
|
||||
|
||||
if __name__ == "__main__":
|
||||
main()
|
Reference in New Issue
Block a user