79124165

Date: 2024-10-25 03:22:23
Score: 1
Natty:
Report link

Hello everyone so after some years i got nostalgic and i actually had solved this 4 years ago but as i notice the post had some 600+ views and no solution until now i just came back to explain what is going on here.

To retrieve specific content, like Thomas-Müntzer-Straße 122 Parking, from a Google search results are dynamically loaded and require dealing with JavaScript content, which means using libraries like Selenium.

So in case anyone still needs it :

from selenium import webdriver

from selenium.webdriver.common.by import By

from selenium.webdriver.chrome.options import Options

chrome_options = Options()

chrome_options.add_argument("--headless") # Run Chrome headless(optional)

chromedriver_path = r"C:\Users\kyria\Downloads\chromedriver-win64\chromedriver-win64\chromedriver.exe"

driver = webdriver.Chrome(executable_path=chromedriver_path, options=chrome_options)

url = 'https://www.google.com/search?q=Thomas+Muntzer+Strasse+122+parking+Gamstadt'

driver.get(url)

driver.implicitly_wait(10) # 10 seconds wait time for elements to load

try: span_element = driver.find_element(By.XPATH,"//span[contains(text(),'Thomas-Müntzer-Straße 122 Parking')]") print(f"Extracted text: {span_element.text}")

except Exception as e: print(f"An error occurred: {e}")

driver.quit()

Reasons:
  • Long answer (-1):
  • No code block (0.5):
  • Contains question mark (0.5):
  • Low reputation (1):
Posted by: Kyrian Bourgi