title: Can I get accurate geolocation in Python using HTML5 location tool?
body: <p>I would like to get my accurate position using a Python script.
  I've tried different services based on IP location, which didn't work at all (always miles away from my actual location).</p>
  
  <p>I noticed that the HTML5 geolocation tool is quite accurate on Firefox &amp; Google Chrome, so I decided to use the selenium module to launch a web browser and grab my position from this.</p>
  
  <p>Though I'm facing 2 issues: first, I can't force either Firefox or Chrome to allow location services on a local webpage. Second, I don't know how to grab the result of a javascript function in which I get my coordinates.</p>
  
  <p>Here's what I've done so far:</p>
  
  <p><strong>geo.html</strong></p>
  
  <pre><code>&lt;html&gt;
      &lt;head&gt;
          &lt;title&gt;Test&lt;/title&gt;
      &lt;p id="demo"&gt;&lt;/p&gt;
          &lt;script type="text/javascript"&gt;
  
  var x = document.getElementById("demo");
  
  function getLocation() {
      if (navigator.geolocation) {
          return navigator.geolocation.getCurrentPosition(showPosition);
      } else {
          return "Geolocation is not supported by this browser.";
      }
  }
  
  
  
  function showPosition(position) {
      x.innerHTML = "Latitude: " + position.coords.latitude +
      "&lt;br&gt;Longitude: " + position.coords.longitude;
  }
          &lt;/script&gt;
      &lt;/head&gt;
      &lt;body&gt;
          &lt;p&gt;The element below will receive content&lt;/p&gt;
          &lt;div id="div" /&gt;
          &lt;script type="text/javascript"&gt;getLocation()&lt;/script&gt;
      &lt;/body&gt;
  &lt;/html&gt;
  </code></pre>
  
  <p><strong>test.py</strong></p>
  
  <pre><code>from selenium import webdriver
  from pyvirtualdisplay import Display
  
  try:
      display = Display(visible=1, size=(800, 600))
      display.start()
      browser = webdriver.Firefox()
      browser.get('file:///path/to/geo.html')
      res = browser.execute_script("getLocation()")
      print(res)
  
  except KeyboardInterrupt:
      browser.quit()
      display.stop()
  </code></pre>
  
  <p>Do you know how to solve this?</p>
  
  <p>Thanks!</p>