Created
March 13, 2021 18:14
-
-
Save samirsaci/afeb0fdb81fb7719fcf9f07697ebd064 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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