当前位置: 首页 > 知识库问答 >
问题:

chromedriver无法获得网站python selenium

毛勇
2023-03-14

我希望我的程序打开默认的chrome配置文件,然后获得YouTube。我可以让它打开youtube(在新的chrome浏览器中),或者打开默认的chrome配置文件,但不能两者兼而有之。(不,我没有运行两个驱动变量

from selenium import webdriver
from selenium.webdriver.chrome.options import Options
import time


print('starting')
print('getting driver')


exec_path= "C:\\Program Files (x86)\\Google\\Chrome\\Application\\chrome.exe"               # exec path from chrome://version

profilePath= 'C:\\Users\\MyName\\AppData\\Local\\Google\\Chrome\\User Data\\Profile 1'      #profile path from chrome://version

chromePath= 'C:\\Users\\MyName\\OneDrive\\Documents\\Python programming\\chromedriver.exe'  #path to driver



options= webdriver.ChromeOptions()

options.add_argument(profilePath)
print('options add argument...')

### Run one or the other ###
driver = webdriver.Chrome(executable_path= chromePath , options=options) #gets youtube
driver = webdriver.Chrome(executable_path= exec_path, options=options) #gets chrome profile


print('webdriver getting youtube...')
driver.get("https://www.youtube.com/")

当我运行获取chrome配置文件的驱动程序行时,我会得到错误:

回溯(最近的调用为last):文件“C:\users\myname\onedrive\documents\python programming\web automation\webauto.py”,第24行,在driver=webdriver.chrome(executable_path=exec_path,options=options)#gets chrome配置文件“C:\users\myname\appdata\local\programs\python\python39\lib\site-packages\selenium\webdriver.py”,第73行,在在启动中引发WebDriverException(“Can not connection to the Service%s”%self.path)Selenium.common.exceptions.WebDriverException:消息:Can not connection to the Service c:\program Files(x86)\google\chrome\application\chrome.exe

共有1个答案

淳于博
2023-03-14

根据你的问题和你的代码测试,如果你想用定制的Chrome配置文件打开Chrome,请尝试使用下面的代码。

from selenium import webdriver
from selenium.webdriver.chrome.options import Options

options = Options()
options.add_argument('C:\\Users\\MyName\\AppData\\Local\\Google\\Chrome\\User Data\\Profile 1' )
driver = webdriver.Chrome(executable_path='C:\\Users\\MyName\\OneDrive\\Documents\\Python programming\\chromedriver.exe', chrome_options=options)
driver.get("https://www.youtube.com/")

在这里,您将找到关于如何通过Python打开Chrome配置文件的详细讨论

 类似资料:
  • 我正在为Java开发人员使用最新的Eclipse IDE中的最新jsoup(1.13.1)(包括孵化组件)版本:2020-09(4.17.0)构建ID:20200910-1200。 我试图解析一个非常具体的网站,但没有成功。在我执行这些行之后:doc=jsoup.connect(“http://pokehb.pw/%d7%a2%d7%95%d7%a0%d7%94/21/%d7%a4%d7%a8%d

  • 我正在尝试使用jsoup登录一个网站,我很确定我正在解析所有需要解析的东西,我只是不知道出了什么问题。 我用这个做参考:http://cs.harding.edu/fmccown/android/Logging-into-Pipeline.pdf 以下是我的AsycntTask doInBackground中的代码: 但问题是,当我登录时,它不包含页面的文档,它包含一个错误页面的文档,该页面只显示

  • 我正在使用这个库:https://github.com/googleapis/google-api-php-client 我创建了一个简单的PHP脚本,从谷歌搜索控制台/网站管理员工具中获取一些关于我拥有的域名性能的信息。 它不打算代表访问页面并拥有自己网站的用户进行自动身份验证。它旨在显示关于我的网站的信息,并通过固定的服务号进行标识。下面更详细。 下面是PHP代码: 因此,我做了以下工作: 在

  • 问题内容: 请帮助我得到一个where 本身就是一个泛型类型。如我现在所见,Spring RestTemplate现在不支持此功能。我正在使用Spring MVC版本3.1.2 这是我要使用的代码:代码: 我收到此错误: 这是明显的错误,但是今天如何解决呢? 比我想得到我的通用响应类型: 现在,我使用此解决方案,并且不使用: 问题答案: 通过引入修复了该问题,你可以显式继承该参数化类型,以便在运行

  • 我试图创建一个程序,在这个程序中我可以接受输入,并用servlet获得一个数字的平方根。我是初学者,所以知道的不多。问题是当我尝试我的代码时,它不起作用。代码如下: myservletdemo.java 结果是:首先,当你点击链接时,你会得到: 这个结果