I am not able to copy the business phone number on Google Maps.
The code below works for most situations but in some cases it doesn't copy the phone
element = 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[9]/div[6]/button")
print(element.get_attribute("aria-label"))
The safest way would be to copy the line below which is where I'm having trouble scraping
CodePudding user response:
You can apply the following way to get the desired data from such a complex scenerio.
from bs4 import BeautifulSoup
from selenium import webdriver
import time
from selenium.webdriver.chrome.service import Service
options = webdriver.ChromeOptions()
webdriver_service = Service("./chromedriver") #Your chromedriver path
driver = webdriver.Chrome(service=webdriver_service)
driver.get("https://www.google.com.br/maps/place/Altas Horas Lanchonete e Petiscaria/@-26.9868563,-48.6408516,18z/data=!4m6!3m5!1s0x94d8b5a98d3ee4bd:0xb2354b88550ca2b4!8m2!3d-26.9867275!4d-48.6399048!16s/g/11k6mwzj5s?authuser=0&hl=pt-BR")
driver.maximize_window()
time.sleep(5)
soup = BeautifulSoup(driver.page_source,"html.parser")
phone = soup.select('.rogA2c')[3].get_text(strip=True)
print(phone)
Output:
55 47 99679-6698