Results 1 to 2 of 2

Using Selenium to get time and distance information from Google Maps

Threaded View

  1. #1
    Registered User
    Join Date
    05-17-2013
    Location
    Duluth, MN
    MS-Off Ver
    Excel 2007
    Posts
    3

    Using Selenium to get time and distance information from Google Maps

    Hi,
    I am trying to make a destination origin matrix, one with distance and one with time, for a linear programming model which needs to have every possible distance and time for a combination of a hundred or so locations. I have downloaded Selenium and my plan is to use google maps to get all of the data, and then I will loop through my locations list to collect all of the data I need. I am having trouble with a few lines of code, basically just pulling the distance and time information from the google maps webpage and putting it into a string. Anyway, any help with the code would be appreciated. The specific line that won't work is the one that assigns the text associated with the xpath to the string.

    Sub Destination_Origin_Matrix()
    Dim driver As New WebDriver
    Dim str As String
    Dim origin As String
    Dim destination As String
       driver.Start "chrome", "http://www.google.com/"                                                     'Launch the browser
       driver.Open "https://www.google.com/maps?m&ll=37.6,-95.665&z=4&output=classic&dg=ntvo"                 'Open to google maps
       driver.Click "id=d_launch"                                                                                          'Click on directions button
       driver.Type "id=d_d", origin                                                                                        'Type the text present in the string origin
       driver.Type "id=d_daddr", destination                                                                         'Type the text present in the string destination
       driver.Click "id=d_launch"                                                                                                         'Click on directions button again to get out of textbox
       driver.Click "id=d_sub"                                                                                           'Click on the "Get Directions" button to get directions
       
    str = driver.findElementsByXPath("//div[@class='altroute-rcol altroute-info']/span[1]").Text                      'should put distance info into str string
       
    driver.stop          'Stop the browser
     End Sub
    Last edited by JKlem; 03-04-2014 at 05:22 PM. Reason: adding code tags

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Similar Threads

  1. Use Google Maps to return driving time and distance
    By KevanC in forum Excel General
    Replies: 2
    Last Post: 12-22-2013, 11:16 PM
  2. Calculate Distance using Google Maps
    By excelinexcel7 in forum Excel General
    Replies: 2
    Last Post: 12-06-2012, 06:19 PM
  3. Query Google maps to return driving distance and time
    By mickisme in forum Excel Programming / VBA / Macros
    Replies: 0
    Last Post: 04-27-2012, 06:18 AM
  4. Use mapquest or google maps to get driving distance?
    By DonkeyOte in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 10-19-2010, 10:04 PM
  5. Use google maps to get distance
    By rdr910 in forum Excel Programming / VBA / Macros
    Replies: 0
    Last Post: 10-13-2010, 09:16 PM

Tags for this Thread

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1