简体   繁体   English

如何使 chromedriver 在 python/selenium 中通用

[英]How to make chromedriver universal in python/selenium

I am working on Python/Selenium, I need to download a chromedriver but unfortunately this does mean that I have to set some sort of a specific path for my chromedriver, when I send this project off to someone how do I make it so they don't have to redownload chromedriver?我正在使用 Python/Selenium,我需要下载一个 chromedriver,但不幸的是,这确实意味着我必须为我的 chromedriver 设置某种特定的路径,当我将此项目发送给某人时,我该如何制作它以便他们不这样做不必重新下载 chromedriver 吗?

Example -例子 -

driver = webdriver.Chrome(executable_path='C:\chromedriver.exe')

So how can I place the chromedriver or what can I do so the executable path doesn't have to be changed?那么如何放置 chromedriver 或者我该怎么做才能不必更改可执行路径?

You need to delete the absolute path and use a relative one.您需要删除绝对路径并使用相对路径。 For example, if you ship your script with chromedriver, and you have both files in the same directory, you can just add a reference to it as if it is in the root directory:例如,如果您使用 chromedriver 发送脚本,并且两个文件都在同一目录中,则可以像在根目录中一样添加对它的引用:

driver = webdriver.Chrome(executable_path='chromedriver.exe')

Or, you can create a folder called resources and hide your chromedriver exe there.或者,您可以创建一个名为资源的文件夹并将您的 chromedriver exe 隐藏在那里。 In this case, your link would be 'resources/chromedriver.exe'.在这种情况下,您的链接将是“资源/chromedriver.exe”。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM