pythonselenium-webdriverweb-scrapingdata-mining

Scrape Company opening amd closing time on Google map


I am trying to get Google Maps Company's opening and closing times with selenium python.

An example link is given bellow :

https://www.google.com/maps/place/Solar+Project+Development+%26+Engineering+Ltd./@23.7988032,90.3525855,17z/data=!3m1!4b1!4m6!3m5!1s0x3755c181e4e00229:0xa17c29dbd5a924f6!8m2!3d23.7988032!4d90.3525855!16s%2Fg%2F11q41jstmd?authuser=0&hl=en&entry=ttu

Here is my code :

class GoogleMapScraperInformation:
    def __init__(self):
        
        self.headless = False
        self.driver = None 


    def config_driver(self):
        options = Options()
        options.add_argument("--start-maximized")

        s = Service(ChromeDriverManager().install())
        driver = webdriver.Chrome(service=s, options=options)
        self.driver = driver


    def get_info(self, url):
        self.driver.get(url)


        try:
            companey_name = self.driver.find_element(By.CLASS_NAME, "lfPIob").text
        except:
            companey_name = ''
        # print(companey_name,"***********")
        
        try:
            address = self.driver.find_element(By.CLASS_NAME, "kR99db").text
        except:
            address = ''
        # print(address,"***********")

I also one step scroll down but I did not find it .

    image_element = self.driver.find_element(By.CLASS_NAME, "lvtCsd img")
    img_result = WebDriverWait(self.driver, 10).until(EC.presence_of_element_located((By.XPATH,'//*[@id="QA0Szd"]/div/div/div[1]/div[2]/div/div[1]/div/div/div[7]/div[5]/a/div[1]/div[2]/div[1]')))
    self.driver.execute_script("arguments[0].scrollIntoView(true);",img_result)

I want to click here :

enter image description here

and after that, I want to get all the opening and closing time

enter image description here


Solution

  • Not sure what is the problem here.

    It can be easily got by clicking on open dropdown icon and waiting for element with aria-label that contains any of week days.

    Then you can parse data by your needs.

    from selenium import webdriver
    from selenium.webdriver.common.by import By
    from selenium.webdriver.support.ui import WebDriverWait
    from selenium.webdriver.support import expected_conditions as EC
    
    driver = webdriver.Chrome()
    
    driver.get("https://www.google.com/maps/place/Solar+Project+Development+%26+Engineering+Ltd./@23.7988032,90.3525855,17z/data=!3m1!4b1!4m6!3m5!1s0x3755c181e4e00229:0xa17c29dbd5a924f6!8m2!3d23.7988032!4d90.3525855!16s%2Fg%2F11q41jstmd?authuser=0&hl=en&entry=ttu")
    wait = WebDriverWait(driver, 20)
    wait.until(EC.visibility_of_element_located((By.CSS_SELECTOR, "[role=button] [role=img]"))).click()
    close_open_el = wait.until(EC.visibility_of_element_located((By.CSS_SELECTOR, "[aria-label*=Thursday]")))
    
    print(close_open_el.text)