Google Map Web Scraping von PythonPython

Python-Programme
Anonymous
 Google Map Web Scraping von Python

Post by Anonymous »

„Ich arbeite daran, den Prozess des Abrufens von Entfernung und Reisezeit zwischen Standorten auf Google Maps mithilfe von Selenium zu automatisieren. Zuvor funktionierte mein Skript einwandfrei, aber jetzt ist ein Problem aufgetreten. Konkret wird die Fehlermeldung „Nein“ ausgegeben Ein solches Element wurde für den Klassennamen „tactile-searchbox-input“ oder ähnliches gefunden. Ich würde mich über Hinweise oder Lösungen zur Lösung dieses Problems freuen!

Code: Select all

from selenium import webdriver
import time
from time import sleep
from selenium.webdriver.common.by import By
from datetime import datetime as dt
import openpyxl
import sys
from selenium.webdriver.support.ui import WebDriverWait
from selenium.webdriver.support import expected_conditions as EC

# set Chrome options to run headless
chrome_options = webdriver.ChromeOptions()
chrome_options.add_argument('--headless')
chrome_options.add_argument('--disable-gpu')

# create Chrome instance with the above options
driver = webdriver.Chrome(options=chrome_options)

# assign url in the webdriver object
driver.get("https://www.google.com/maps/@33.9650923,71.5293553,9942m/data=!3m1!1e3?entry=ttu&g_ep=EgoyMDI0MTIxMS4wIKXMDSoJLDEwMjExMjMzSAFQAw%3D%3D")
sleep(5)

# search locations
def searchplace():

Place = driver.find_element(By.CLASS_NAME, "tactile-searchbox-input")
Place.send_keys("33.983515, 71.447372")
submit = driver.find_element(By.XPATH,"/html/body/div[1]/div[3]/div[8]/div[3]/div[1]/div[1]/div/div[2]/div[1]/button")
submit.click()

# get directions
def directions():

directions = driver.find_element(By.XPATH, "/html/body/div[1]/div[3]/div[8]/div[9]/div/div/div[1]/div[2]/div/div[1]/div/div/div[4]/div[1]/button")
directions.click()

# Start Point
def Start_Point():
Starting_Location=driver.find_element(By.XPATH,"/html/body/div[3]/div[9]/div[3]/div[1]/div[2]/div/div[3]/div[1]/div[1]/div[2]/div[1]/div/input")
Starting_Location.clear()
Starting_Location.send_keys("33.99891877029553, 71.40166320892853") # Starting Location Input
Search = driver.find_element(By.XPATH,"/html/body/div[3]/div[9]/div[3]/div[1]/div[2]/div/div[3]/div[1]/div[1]/div[2]/button[1]")
Search.click()

# Printing Data
def Print_info():
Distance = driver.find_element(By.XPATH,"/html/body/div[3]/div[9]/div[9]/div/div/div[1]/div[2]/div/div[1]/div/div/div[4]/div[1]/div[1]/div/div[1]/div[1]")
Travel_Time = driver.find_element(By.XPATH,"/html/body/div[3]/div[9]/div[9]/div/div/div[1]/div[2]/div/div[1]/div/div/div[4]/div[1]/div[1]/div/div[1]/div[2]")
return Distance.text,Travel_Time.text
# Set start time
start_time_str = '11:05 AM'  # Change to your desired start time
start_time = dt.strptime(start_time_str, '%I:%M %p').time()

# Set end time
end_time_str = '6:50 PM'  # Change to your desired end time
end_time = dt.strptime(end_time_str, '%I:%M %p').time()
i=0
while True:
# Get current time
now = dt.now().time()

# Check if current time is within the specified time range
if start_time

Quick Reply

Change Text Case: 
   
  • Similar Topics
    Replies
    Views
    Last post