如何使用Python在Selenium WebDriver中获取用户代理信息

时间:2018-07-23 15:45:43

标签: python selenium selenium-webdriver web-scraping selenium-chromedriver

我正在尝试使用chromedriver获得当前在Selenium中使用的实际用户代理。

我找到了此问题的Java版本: How to get userAgent information in Selenium Web driver

有人知道如何在Python中做到这一点吗?

1 个答案:

答案 0 :(得分:6)

与链接内部相同:

user_agent = driver.execute_script("return navigator.userAgent;")

PS:使用execute_script方法可以在驱动程序中运行JS。

希望对您有帮助!