【发布时间】:2020-08-08 01:59:46
【问题描述】:
我在 Mac 上,我正在尝试将 selenium 与 phantomjs 一起使用。我已经从他们的网站下载了适用于 mac 的 phantomjs 可执行文件,但我不知道将它放在哪里以便 selenium 使用它。我正在使用 Visual Studio Code、Mac 和 python 3.7。谢谢
【问题讨论】:
标签: python selenium selenium-webdriver phantomjs
我在 Mac 上,我正在尝试将 selenium 与 phantomjs 一起使用。我已经从他们的网站下载了适用于 mac 的 phantomjs 可执行文件,但我不知道将它放在哪里以便 selenium 使用它。我正在使用 Visual Studio Code、Mac 和 python 3.7。谢谢
【问题讨论】:
标签: python selenium selenium-webdriver phantomjs
把它放在任何地方!是的,任何地方。即使我把它放在一个名为 setups 的单独文件夹中,我也存储了所有 webdrivers,包括PhantomJS.exe。它运作良好。没有错误。
只需将其添加到代码本身的路径中即可:
driver = webdriver.PhantomJS(executable_path=r"C:\Users\intel\Downloads\setups\PhantomJS.exe")
要么像我上面那样在路径名之后使用PhantomJS.exe,要么只使用PhantomJS。
编辑:
PhantomJS 支持最近已经结束,因为它太旧了,不再维护。您收到的消息不是错误,而是警告。我更喜欢你在这里使用 chrome 浏览器。
您甚至可以制作 chrome 浏览器 headless 就像 PhantomJS 一样。
为此:
from selenium.webdriver.chrome.options import Options
options = Options()
options.add_argument("--headless")
driver = webdriver.Chrome(executable_path=r"C:\Users\intel\Downloads\setups\chromedriver.exe", options=options)
也不要忘记像我一样在路径末尾使用options=options。
【讨论】: