擅长:python、mysql、java
<p>首先,要在无头模式下使用Selenium,必须定义屏幕大小</p>
<pre class="lang-py prettyprint-override"><code>options.add_argument(' window-size=1920,1080')
</code></pre>
<p>要获得坐标和速度,可以使用以下命令:</p>
<pre class="lang-py prettyprint-override"><code>from selenium.webdriver.common.by import By
from selenium.webdriver.support.ui import WebDriverWait
from selenium.webdriver.support import expected_conditions as EC
wait = WebDriverWait(driver, 20)
coordinates = wait.until(EC.visibility_of_element_located((By.XPATH, "//p[contains(text(),'Latitude')]/b"))).text
speed = wait.until(EC.visibility_of_element_located((By.XPATH, "//p[contains(text(),'Speed')]/b"))).text
</code></pre>
<p>此外,由于您使用的是无头模式,这些设置可能有用</p>
<pre class="lang-py prettyprint-override"><code>options.add_argument(' no-sandbox')
options.add_argument(' disable-dev-shm-usage')
</code></pre>