我开始自动化无聊的东西书,我正在尝试通过python打开一个chrome web浏览器.我已经安装了硒和
我试过运行这个文件:
from selenium import webdriver
from selenium.webdriver.common.by import By
from selenium.webdriver.common.keys import Keys
browser = webdriver.Chrome()
browser.get('https://automatetheboringstuff.com')
Run Code Online (Sandbox Code Playgroud)
但正因为如此,我得到这个错误:
Traceback (most recent call last): File "C:\Program Files
(x86)\Python36-32\lib\site-packages\selenium\webdriver\common\service.py",
line 74, in start
stdout=self.log_file, stderr=self.log_file) File "C:\Program Files (x86)\Python36-32\lib\subprocess.py", line 707, in __init__
restore_signals, start_new_session) File "C:\Program Files (x86)\Python36-32\lib\subprocess.py", line 990, in _execute_child
startupinfo) FileNotFoundError: [WinError 2] The system cannot find the file specified
Run Code Online (Sandbox Code Playgroud)
在处理上述异常期间,发生了另一个异常:
Traceback (most recent call last): File "C:/Program Files
(x86)/Python36-32/test.py", line 5, in <module>
browser = …Run Code Online (Sandbox Code Playgroud) 我今天开始了一个硒教程,并在尝试运行代码时遇到了这个错误。我尝试过其他方法但最终得到了同样的错误。我在 MacOS 上使用 VSC。
我的代码:
from selenium import webdriver
PATH = '/Users/blutch/Documents/Chrom Web Driver\chromedriver.exe'
driver = webdriver.Chrome(PATH)
driver.get("https://www.google.com")
Run Code Online (Sandbox Code Playgroud)
我还尝试在 /Users 前面插入 C:。谁能指导我为什么会发生这种情况/如何解决它?
我已经升级到 Selenium 4
new_binary_path = FirefoxBinary('path_to_binary')
selenium.webdriver.Firefox(executable_path=path, options=ops, firefox_binary=new_binary_path)
Run Code Online (Sandbox Code Playgroud)
或者
options.add_argument("--setBinary(path_to_binary)")
selenium.webdriver.Firefox(executable_path=path, options=ops)
Run Code Online (Sandbox Code Playgroud)
返回此错误信息
DeprecationWarning: executable_path has been deprecated, please pass in a Service object
Run Code Online (Sandbox Code Playgroud)
文档
https://github.com/SeleniumHQ/selenium/blob/master/javascript/node/selenium-webdriver/CHANGES.md
说
删除了 firefox.Binary 类。仍然可以使用 firefox.Options#setBinary() 选择自定义二进制文件。同样,可以使用 firefox.Options#addArguments() 指定自定义二进制参数
有谁知道如何实施这些更改?我不知道标签是什么意思。我尝试过options.setBinary()但setBinary()没有被识别。
我已经在我的windows-10系统上安装了 webdrivermanager
C:\Users\username>pip install webdrivermanager
Requirement already satisfied: webdrivermanager in c:\python\lib\site-packages (0.8.0)
Requirement already satisfied: lxml in c:\python\lib\site-packages (from webdrivermanager) (4.5.1)
Requirement already satisfied: requests in c:\python\lib\site-packages (from webdrivermanager) (2.20.1)
Requirement already satisfied: tqdm in c:\python\lib\site-packages (from webdrivermanager) (4.46.1)
Requirement already satisfied: appdirs in c:\python\lib\site-packages (from webdrivermanager) (1.4.4)
Requirement already satisfied: BeautifulSoup4 in c:\python\lib\site-packages (from webdrivermanager) (4.6.0)
Requirement already satisfied: certifi>=2017.4.17 in c:\python\lib\site-packages (from requests->webdrivermanager) (2018.11.29)
Requirement already satisfied: chardet<3.1.0,>=3.0.2 in c:\python\lib\site-packages (from requests->webdrivermanager) (3.0.4)
Requirement already satisfied: …Run Code Online (Sandbox Code Playgroud) python selenium sublimetext3 windows-10 webdrivermanager-python
如何使 webdriver_manager.chrome 使用自定义 chrome 用户配置文件?
我知道对于 selenium webdriver 我可以这样指定:
options = Options()
options.add_argument(f'user-data-dir={script_path}\\User Data\\profile')
driver = webdriver.Chrome(executable_path=f'{script_path}\\chromedriver.exe', options=options)
Run Code Online (Sandbox Code Playgroud)
但由于我想让 chromedriver 自己安装正确的版本(因为我将程序出售给非 python 用户),所以我使用的是 webdriver_manager 模块,如下所示:
driver = webdriver.Chrome(ChromeDriverManager().install())
Run Code Online (Sandbox Code Playgroud)
有什么方法可以加载自定义配置文件,以便在使用 webdriver_manager 时将网站上的登录数据保存在我的配置文件中?
python selenium webdriver selenium-chromedriver webdriver-manager
运行此代码时:
\nfrom selenium import webdriver\nfrom selenium.webdriver.common.keys import Keys\nfrom webdrivermanager.chrome import ChromeDriverManager\n\ndriver = webdriver.Chrome(ChromeDriverManager().download_and_install())\ndriver.get("http://www.python.org")\nRun Code Online (Sandbox Code Playgroud)\n这会导致安装 chromedriver 的行出现以下异常:
\n\n\n类型错误:需要 str、bytes 或 os.PathLike 对象,而不是元组
\n
请注意,我知道已经存在许多关于此主题的线程,但由于 webdrivermanager 似乎已主要更新,以前的解决方案不起作用。
\n还有一个简短的旁注:我通过 conda 而不是 pip 安装了 webdrivermager。但这不应该令人担忧。
\n编辑:整个堆栈跟踪:
\n\n回溯(最近一次调用最后一次):文件“C:\\Users\\stefa\\OneDrive -\nJohannes Kepler Universit\xc3\xa4t\nLinz\\Dokumente\\GitHub\\briefly\\src\\crawler\\crawler .py”,第 19 行,\n\ndriver = webdriver.Chrome(ChromeDriverManager().download_and_install()) 文件\n“C:\\Users\\stefa\\anaconda3\\envs\\briefly\\lib\ \site-packages\\selenium\\webdriver\\chrome\\webdriver.py",\n第 73 行,在init \nself.service.start() 文件“C:\\Users\\stefa\\anaconda3\\envs \\briefly\\lib\\site-packages\\selenium\\webdriver\\common\\service.py",\n第 72 行,在 start\nself.process = subprocess.Popen(cmd, env=self.env,文件“C:\\Users\\stefa\\anaconda3\\envs\\briefly\\lib\\subprocess.py”,第951行,\nin init \nself._execute_child(args,可执行文件,preexec_fn,close_fds,文件“ C:\\Users\\stefa\\anaconda3\\envs\\briefly\\lib\\subprocess.py", line\n1360, in _execute_child\nargs = list2cmdline(args) 文件 "C:\\Users\\stefa \\anaconda3\\envs\\briefly\\lib\\subprocess.py",第 565 行,\nin list2cmdline\nfor arg in …
python selenium selenium-chromedriver selenium-webdriver webdriver-manager
我刚刚开始使用seleniumPython,并且不断收到以下错误代码:
TypeError: WebDriver.__init__() got an unexpected keyword argument 'executable_path'
Run Code Online (Sandbox Code Playgroud)
这是上下文的代码:
from selenium.webdriver import Firefox
from selenium.webdriver.common.keys import Keys
url = 'https://example'
driver_path = r"D:\path\to\geckodriver.exe"
browser = Firefox(executable_path=driver_path)
browser.get(url)
Run Code Online (Sandbox Code Playgroud)
提前致谢!
我检查了路径、selenium包的版本并确保我有正确的geckodriver.exe但仍然收到错误。
python ×6
selenium ×6
python-3.x ×2
firefox ×1
geckodriver ×1
sublimetext3 ×1
webdriver ×1
windows-10 ×1