Skip to content

Instantly share code, notes, and snippets.

@samirsaci
Created March 13, 2021 18:14
Show Gist options
  • Save samirsaci/afeb0fdb81fb7719fcf9f07697ebd064 to your computer and use it in GitHub Desktop.
Save samirsaci/afeb0fdb81fb7719fcf9f07697ebd064 to your computer and use it in GitHub Desktop.
def from_to(fr, to):
# create irl
url = 'https://www.google.fr/maps/dir/{}/{}/data=!4m2!4m1!3e0'.format(fr, to)
# Connect to the page
driver.get(url)
# Wait 1 sec to ensure full page is loaded
time.sleep(1)
# Soupify source code
page_soup = soup(driver.page_source, "html.parser")
# Extract Distance
css_dist = "div[class^='section-directions-trip-distance'] > div"
# Distance value + unit
distance = page_soup.select_one(css_dist).text
# Format dictionnary
result = {"distance": distance}
return result
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment