-
2020-02-24 12:08:34
通过源码看解释
最直接最不讲道理的方式就是看源码,使用之前一定要学会看说明书。
打算使用jupyter演示的,但是jupyter不支持看源码,所以使用Pycharm吧。
from selenium import webdriver Broswer = webdriver.Chrome(executable_path="chromedriver", port=0, options=None, service_args=None, desired_capabilities=None, service_log_path=None, chrome_options=None, keep_alive=True) print(webdriver.Chrome.__doc__) """ Controls the ChromeDriver and allows you to drive the browser. You will need to download the ChromeDriver executable from http://chromedriver.storage.googleapis.com/index.html """ print(webdriver.Chrome.__init__.__doc__) """ Creates a new instance of the chrome driver. Starts the service and then creates new instance of chrome driver. :Args: - executable_path - path to the executable. If the default is used it assumes the executable is in the $PATH - port - port you would like the service to run, if left as 0, a free port will be found. - options - this takes an instance of ChromeOptions - service_args - List of args to pass to the driver service - desired_capabilities - Dictionary object with non-browser specific capabilities only, such as "proxy" or "loggingPref". - service_log_path - Where to log information from the driver. - chrome_options - Deprecated argument for options - keep_alive - Whether to configure ChromeRemoteConnection to use HTTP keep-alive. """
Chrome Doc解释: 控制ChromeDriver并允许您驱动浏览器。你需要从
http://chromedriver.storage.googleapis.com/index.html
下载ChromeDriver的可执行文件。没有下ChromeDriver的小伙伴根据自己浏览器版本下载相应的ChromeDriver版本,两者版本关系ChromeDriver版本>=Chrome版本。参数解释:
-
executable_path - 可执行文件的路径。如果使用默认值,则假定可执行文件位于$PATH中。
-
port- 你希望服务运行的端口,如果为0,使用空闲端口。
-
options - 这是ChromeOptions的一个实例
-
service_args - 要传递给驱动程序服务的args列表
-
desired_capabilities -仅具有非浏览器特定功能的字典对象,例如“proxy”或“loggingPref”。
-
service_log_path - 记录来自驱动程序的信息存放路径。
-
chrome_options - chrome选项。
-
keep_alive -是否配置ChromeRemoteConnection使用HTTP keep-alive。
其中
options
和chrome_options
:使用options代替chrome_options。if chrome_options: warnings.warn('use options instead of chrome_options', DeprecationWarning, stacklevel=2) options = chrome_options
并且告知此警告被弃用
关于
executable_path
解释:value是ChromeDriver.exe路径。更多相关内容 -
-
驱动程序可执行文件的路径必须由webdriver.chrome.driver系统属性(php)设置
2021-05-07 03:39:08我只是切换到Ubuntu操作系统,现在我在...驱动程序可执行文件的路径必须由webdriver.chrome.driver系统属性(php)设置硒服务器08:58:49.965 INFO - Launching a standalone Selenium Server08:58:49.986 INFO -...我在运行我的php selenium测试时遇到了问题。我只是切换到Ubuntu操作系统,现在我在selenium服务器上收到了这个异常堆栈。驱动程序可执行文件的路径必须由webdriver.chrome.driver系统属性(php)设置
硒服务器
08:58:49.965 INFO - Launching a standalone Selenium Server
08:58:49.986 INFO - Java: Oracle Corporation 25.101-b13
08:58:49.986 INFO - OS: Linux 4.4.0-36-generic amd64
08:58:49.996 INFO - v2.53.0, with Core v2.53.0. Built from revision 35ae25b
08:58:50.040 INFO - Driver provider org.openqa.selenium.ie.InternetExplorerDriver registration is skipped:
registration capabilities Capabilities [{ensureCleanSession=true, browserName=internet explorer, version=, platform=WINDOWS}] does not match the current platform LINUX
08:58:50.041 INFO - Driver provider org.openqa.selenium.edge.EdgeDriver registration is skipped:
registration capabilities Capabilities [{browserName=MicrosoftEdge, version=, platform=WINDOWS}] does not match the current platform LINUX
08:58:50.041 INFO - Driver class not found: com.opera.core.systems.OperaDriver
08:58:50.041 INFO - Driver provider com.opera.core.systems.OperaDriver is not registered
08:58:50.041 INFO - Driver provider org.openqa.selenium.safari.SafariDriver registration is skipped:
registration capabilities Capabilities [{browserName=safari, version=, platform=MAC}] does not match the current platform LINUX
08:58:50.042 INFO - Driver class not found: org.openqa.selenium.htmlunit.HtmlUnitDriver
08:58:50.042 INFO - Driver provider org.openqa.selenium.htmlunit.HtmlUnitDriver is not registered
08:58:50.075 INFO - RemoteWebDriver instances should connect to: http://127.0.0.1:4444/wd/hub
08:58:50.075 INFO - Selenium Server is up and running
08:59:41.556 INFO - Executing: [new session: Capabilities [{browserName=chrome, platform=LINUX}]])
08:59:41.566 INFO - Creating a new session for Capabilities [{browserName=chrome, platform=LINUX}]
08:59:41.573 WARN - Exception thrown
java.util.concurrent.ExecutionException: org.openqa.selenium.WebDriverException: java.lang.reflect.InvocationTargetException
Build info: version: '2.53.0', revision: '35ae25b', time: '2016-03-15 17:00:58'
System info: host: 'Keson', ip: '127.0.1.1', os.name: 'Linux', os.arch: 'amd64', os.version: '4.4.0-36-generic', java.version: '1.8.0_101'
Driver info: driver.version: unknown
at java.util.concurrent.FutureTask.report(FutureTask.java:122)
at java.util.concurrent.FutureTask.get(FutureTask.java:192)
at org.openqa.selenium.remote.server.DefaultSession.execute(DefaultSession.java:183)
at org.openqa.selenium.remote.server.DefaultSession.(DefaultSession.java:119)
at org.openqa.selenium.remote.server.DefaultSession.createSession(DefaultSession.java:95)
at org.openqa.selenium.remote.server.DefaultDriverSessions.newSession(DefaultDriverSessions.java:124)
at org.openqa.selenium.remote.server.handler.NewSession.handle(NewSession.java:59)
at org.openqa.selenium.remote.server.handler.NewSession.handle(NewSession.java:1)
at org.openqa.selenium.remote.server.rest.ResultConfig.handle(ResultConfig.java:111)
at org.openqa.selenium.remote.server.JsonHttpCommandHandler.handleRequest(JsonHttpCommandHandler.java:79)
at org.openqa.selenium.remote.server.DriverServlet.handleRequest(DriverServlet.java:204)
at org.openqa.selenium.remote.server.DriverServlet.doPost(DriverServlet.java:166)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:707)
at org.openqa.selenium.remote.server.DriverServlet.service(DriverServlet.java:132)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:790)
at org.openqa.jetty.jetty.servlet.ServletHolder.handle(ServletHolder.java:428)
at org.openqa.jetty.jetty.servlet.ServletHandler.dispatch(ServletHandler.java:680)
at org.openqa.jetty.jetty.servlet.ServletHandler.handle(ServletHandler.java:571)
at org.openqa.jetty.http.HttpContext.handle(HttpContext.java:1526)
at org.openqa.jetty.http.HttpContext.handle(HttpContext.java:1479)
at org.openqa.jetty.http.HttpServer.service(HttpServer.java:920)
at org.openqa.jetty.http.HttpConnection.service(HttpConnection.java:820)
at org.openqa.jetty.http.HttpConnection.handleNext(HttpConnection.java:986)
at org.openqa.jetty.http.HttpConnection.handle(HttpConnection.java:837)
at org.openqa.jetty.http.SocketListener.handleConnection(SocketListener.java:243)
at org.openqa.jetty.util.ThreadedServer.handle(ThreadedServer.java:358)
at org.openqa.jetty.util.ThreadPool$PoolThread.run(ThreadPool.java:537)
Caused by: org.openqa.selenium.WebDriverException: java.lang.reflect.InvocationTargetException
Build info: version: '2.53.0', revision: '35ae25b', time: '2016-03-15 17:00:58'
System info: host: 'Keson', ip: '127.0.1.1', os.name: 'Linux', os.arch: 'amd64', os.version: '4.4.0-36-generic', java.version: '1.8.0_101'
Driver info: driver.version: unknown
at org.openqa.selenium.remote.server.DefaultDriverProvider.callConstructor(DefaultDriverProvider.java:113)
at org.openqa.selenium.remote.server.DefaultDriverProvider.newInstance(DefaultDriverProvider.java:97)
at org.openqa.selenium.remote.server.DefaultDriverFactory.newInstance(DefaultDriverFactory.java:60)
at org.openqa.selenium.remote.server.DefaultSession$BrowserCreator.call(DefaultSession.java:222)
at org.openqa.selenium.remote.server.DefaultSession$BrowserCreator.call(DefaultSession.java:1)
at java.util.concurrent.FutureTask.run(FutureTask.java:266)
at org.openqa.selenium.remote.server.DefaultSession$1.run(DefaultSession.java:176)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1142)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:617)
at java.lang.Thread.run(Thread.java:745)
Caused by: java.lang.reflect.InvocationTargetException
at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
at sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:62)
at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45)
at java.lang.reflect.Constructor.newInstance(Constructor.java:423)
at org.openqa.selenium.remote.server.DefaultDriverProvider.callConstructor(DefaultDriverProvider.java:103)
... 9 more
Caused by: java.lang.IllegalStateException: The path to the driver executable must be set by the webdriver.chrome.driver system property; for more information, see https://github.com/SeleniumHQ/selenium/wiki/ChromeDriver. The latest version can be downloaded from http://chromedriver.storage.googleapis.com/index.html
at com.google.common.base.Preconditions.checkState(Preconditions.java:199)
at org.openqa.selenium.remote.service.DriverService.findExecutable(DriverService.java:109)
at org.openqa.selenium.chrome.ChromeDriverService.access$0(ChromeDriverService.java:1)
at org.openqa.selenium.chrome.ChromeDriverService$Builder.findDefaultExecutable(ChromeDriverService.java:137)
at org.openqa.selenium.remote.service.DriverService$Builder.build(DriverService.java:296)
at org.openqa.selenium.chrome.ChromeDriverService.createDefaultService(ChromeDriverService.java:88)
at org.openqa.selenium.chrome.ChromeDriver.(ChromeDriver.java:138)
... 14 more
08:59:41.576 WARN - Exception: The path to the driver executable must be set by the webdriver.chrome.driver system property; for more information, see https://github.com/SeleniumHQ/selenium/wiki/ChromeDriver. The latest version can be downloaded from http://chromedriver.storage.googleapis.com/index.html
Chromdriver运行
Starting ChromeDriver (v2.9.248304) on port 9515
当我运行测试
There was 1 error:
UnknownServerException: The path to the driver executable must be set by the webdriver.chrome.driver system property; for more information, see https://github.com/SeleniumHQ/selenium/wiki/ChromeDriver. The latest version can be downloaded from http://chromedriver.storage.googleapis.com/index.html
为什么这个问题sudenlly出现,这是一个错误?如何解决它?如果您需要任何其他信息,请让我知道,我会提供。 预先感谢您
2016-09-16
Valor_
+0
这个错误是由什么命令造成的? –
-
selenium使用 webdriver.Chrome() 报错,找不到执行文件的解决方法(一)
2022-03-03 18:10:08(1)在webdriver.Chrome()中添加executable_path参数,参数value = chromedriver.exe文件所在路径,示例: from selenium import webdriver chrome_driver_path = "D:\Chrome\chromedriver\chromedriver.exe" dr使用 driver = webdriver.Chrome() 时,遇到以下报错:
selenium.common.exceptions.WebDriverException: Message: 'chromedriver' executable needs to be in PATH.
两种解决方法:
(1)在webdriver.Chrome()中添加executable_path参数,参数value = chromedriver.exe文件所在路径,示例:from selenium import webdriver
chrome_driver_path = "D:\Chrome\chromedriver\chromedriver.exe"
driver = webdriver.Chrome(executable_path=chrome_driver_path)
driver.get("http://baidu.com")(2)修改webdriver.Chrome()源码中的默认执行路径,将DEFAULT_EXECUTEABLE_PATH修改为本地chromedriver.exe文件所在路径,示例:
-
Python3 + selenium + Chrome浏览器(webdriver.Chrome()报错)
2021-03-07 03:10:03python3 + selenium + chrome浏览器error:selenium.common.exceptions.webdriverexception: message: 'chromedriver' executable needs to be in path.please see ...python3 + selenium + chrome浏览器
error:
selenium.common.exceptions.webdriverexception: message: 'chromedriver' executable needs to be in path.please see https://sites.google.com/a/chromium.org/chromedriver/home
这是因为调用 webdriver.chrome() 需要设置参数 executable_path,而executable_path 为chromedriver.exe所在地址。
chromedriver.exe的下载地址为 http://chromedriver.storage.googleapis.com/index.html
首先需要确定本机的chrome浏览器的版本,在chrome浏览器里输入"chrome://version"即可,如下图,google chrome冒号后面即为对应版本。本机的chrome版本为75.0.3770.142,下载地址中并无完全吻合的版本,最后下载了75.0.3770.142版本对应的亦可兼容本机。
这是下载地址界面:
然后我们转到对应版本界面,选择对应系统的zip文件下载并解压。
得到chromedriver.exe文件后,给 webdriver.chrome() 添加参数 executable_path = 'path/chromedriver.exe'(path为chromedriver.exe所在的目录)
之后我的代码就运行成功了
如您对本文有疑问或者有任何想说的,请点击进行留言回复,万千网友为您解惑!
-
DeprecationWarning: use options instead of chrome_options driver = webdriver.Chrome(path, chrome_o
2022-01-06 09:12:00使用selenium进行获取一些数据时,运行时一直报警告:‘DeprecationWarning: use options instead of chrome_options driver = webdriver.Chrome(path, chrome_options=option)’ 虽然不是个错误,但还是解决一下,... -
DeprecationWarning: use options instead of chrome_options driver = webdriver.Chrome(chrome_options
2021-04-29 11:21:26问题 在执行如下代码时报警告 options = webdriver.ChromeOptions() ...DeprecationWarning: use options instead of chrome_options driver = webdriver.Chrome(chrome_options=option, executable_path -
selenium中webdriver.Chrome()的返回对象的session值详解
2020-04-13 20:08:08打开一个浏览器: ``` from selenium import webdriver import time # 创建Chrome驱动程序的新实例 driver = webdriver.Chrome() print(type(driver)) print(driver) # 转到百度主页 driver.get(... -
selenium.webdriver.chrome.options 中add_argument 常用参数表
2020-02-26 18:56:28eg: chrome_options.add_argument('--incognito') # 设置Chrome为隐身模式(无痕模式) 1 --allow-outdated-plugins 不停用过期的插件。 2 --allow-running-insecure-content 默认情... -
Python在使用webdriver.chrome查js内容太慢
2020-08-09 17:17:42参考链接:https://www.cnblogs.com/darkspr/p/11533119.html 设置参数,让driver.get()方法不阻塞,亲测速度比之前的提升了不少,记录下! -
python selenium webdriver.chrome 获取属性的值(可以获取隐藏元素内的文本的一直方法)
2020-11-29 00:14:10driver = webdriver.Chrome(executable_path="chromedriver.exe") innerHTML = driver.find_elements_by_css_selector("#dologin")[0].get_attribute('innerText') -
selenium的webdriver.Chrome()
2018-11-17 18:32:55文章目录selenium.webdriver.Chrome()simple examplesome problems selenium.webdriver.Chrome() Selenium requires a driver to interface with the chosen browser. simple example from selenium import ... -
webdriver.Chrome()报错:selenium.common.exceptions.WebDriverException: Message: 'chromedriver' ...
2018-03-11 11:35:29使用selenium模块的webdriver打开谷歌浏览器的时候报错。...browser = webdriver.Chrome() print(type(browser)) browser.get('https://www.baidu.com')错误信息如下:Traceback (most recent call last):... -
selenium webdriver.Chrome()出现 'chromedriver' executable needs to be in PATH的问题
2018-09-17 23:57:02出现这个问题首先要确认是否下载了chromedriver,如果确认下载了, ...在申明Chrome为浏览器驱动对象时加上chromedriver的路径参数即可 brower = webdriver.Chrome('/Users/zhangxin/Downloads/chromedriver')... -
webdriver.Chrome()提示--ignore-certificate-errors
2018-08-09 20:15:22webdriver.Chrome()提示–ignore-certificate-errors 在配置好chromedriver的path之后,运行webdriver.Chrome(chromedriver),会弹出浏览器,但是浏览器报错显示:ignore-certificate-errors 原因:是你下载的... -
webdriver.chrome()禁止加载图片
2018-12-28 15:48:00webdriver.chrome()禁止加载图片 from selenium import webdriver chrome_options = webdriver.ChromeOptions() prefs = {"profile.managed_default_content_settings.images": 2} chrome_options.add_... -
python+selenium webdriver.firefox()方式配置浏览器设置
2020-12-10 15:24:59webdriver.firefox()爬虫需求: (其实是输入参数可获取.zip/pdf 文件,然后点击下载)——但是firefox浏览器有Bug,点击下载之后会有弹出窗口,需要你点击确定,这怎么能成,所以百度一把:得知需要修改firefox的配置... -
python chrome webdriver参数
2020-09-23 17:52:555.2. chrome实用参数 其他的一些关于Chrome的实用参数及简要的中文说明,使用方法同上4.5.4,当然也可以在shell中使用。 –user-data-dir=”[PATH]” 指定用户文件夹User Data路径,可以把书签这样的用户数据... -
Python Selenium.WebDriver 浏览器启动参数设置『Edge如何使用启动参数』
2021-10-24 01:19:54在创建 WebDriver 实例时,可以配置它的启动参数以进行一些初始设置,这些设置将会在 WebDriver 的整个生命周期内生效 对于不同类型的浏览器,WebDriver 传入的参数并不相同,但主要的几个参数是一样的* -
终于解决了 selenium 模块 webdriver.Edge 运行报错的问题了
2020-01-16 22:08:23终于解决selenium模块webdriver.Edge运行报错的问题了解决过程解决方法1 下载webdriver2 copy文件3 代码附图 解决过程 馍馍片。。。花了好几个小时,终于解决了这个烦人的问题。大概是第一篇不用重装浏览器的方法... -
webdriver.Chrome.set_network_conditions:Chrome网络仿真设置。
2020-02-24 12:37:36参数 print(webdriver.Chrome.set_network_conditions.__doc__) """ Sets Chrome network emulation settings. :Args: - network_conditions: A dict with conditions specification. :Usa... -
Selenium Webdriver之Chrome浏览器操作小记
2018-12-12 15:30:45# driver = webdriver.Chrome() # 设置了chromedriver的环境变量,则此行代码等效于上面两行代码 driver . get ( "https://www.baidu.com" ) # 查找元素 search_btn = driver . find_element_by_id ( 'su' ) ... -
Selenium+Java+Webdriver+Chrome登录操作 谷歌浏览器通过设置启动参数保存登陆状态
2020-07-30 16:56:38网上这块设置参数的java的太少了,通过不懈努力,终于实现了,记录一下: 需要注意的是如果有正在运行的浏览器正在运行,用户文件就读取不成功,所以必须在运行前将谷歌浏览器的窗口全部关闭 package ... -
Selenium.Webdriver最新语法教程(附Chrome实例演示)
2022-05-02 14:14:49模拟按键对应字符串对照列表 根据需求按照目录自由跳转学习即可 驱动下载与导入 点击链接Chrome Webdriver下载入口选择当前浏览器版本对应的驱动 Pycharm 导入 selenium包 驱动提取 from selenium import webdriver ... -
selenium webdriver操作chrome options、 启用无痕模式、缓存烦恼
2022-04-05 16:49:19当启用浏览器打开网页的时候,可以直接启用无痕模式,省去清理缓存这一步骤。 初始化ChromeOptions 并设置"–incognito" ChromeOptions options = new ChromeOptions(); options.AddArgument("–...启动参数 作用 -
webdriver启动chrome浏览器后打不开URL
2021-09-22 16:04:19一、运行webdriver用例时可以启动浏览器,然后就不动了,不能打开url,可能就是版本不对应。chrome版本和chromedriver.exe版本对应如下图: