如何使用 Python 在 Selenium WebDriver 中获取用户代理信息 [英] How to get user agent information in Selenium WebDriver with Python

查看:36
本文介绍了如何使用 Python 在 Selenium WebDriver 中获取用户代理信息的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试使用 chromedriver 获取我在 Selenium 中使用的实际用户代理.

I am trying to get the actual user agent that I am using in Selenium, at the moment with the chromedriver.

我发现了这个问题的 Java 版本:如何在 Selenium Web 驱动程序中获取 userAgent 信息.

I found a Java version of this problem: How to get userAgent information in Selenium Web driver.

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

Does someone know how to do that in Python?

推荐答案

与您的链接内的方式相同:

The same manner as inside your link:

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

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

PS: Using execute_script method you can run JS inside your driver.

希望对你有帮助!

这篇关于如何使用 Python 在 Selenium WebDriver 中获取用户代理信息的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆