1

我一直在尝试在 Kali linux 中自动化我的 firefox 浏览器。我安装了 selenium 和 geckdriver 并运行了这个简单的脚本:

from selenium import webdriver
browser = webdriver.Firefox('/usr/bin/')
browser.get('www.duckduckgo.com')

#I saw a video where the guy mentioned that we do not have to use the path of the browser (doesn't work for me)

在 python 中运行这个简单的脚本后, python3 script.py 终端冻结在:

script.py:4: DeprecationWarning: firefox_profile has been deprecated, please pass in a Service object

中断进程后,它会提供以下错误:

  browser = webdriver.Firefox('/usr/bin/')
^CTraceback (most recent call last):
  File "script.py", line 4, in <module>
    browser = webdriver.Firefox('/usr/bin/')
  File "/usr/lib/python3/dist-packages/selenium/webdriver/firefox/webdriver.py", line 155, in __init__
    firefox_profile = FirefoxProfile(firefox_profile)
  File "/usr/lib/python3/dist-packages/selenium/webdriver/firefox/firefox_profile.py", line 78, in __init__
    ignore=shutil.ignore_patterns("parent.lock", "lock", ".parentlock"))
  File "/usr/lib/python3.7/shutil.py", line 354, in copytree
    copy_function(srcname, dstname)
  File "/usr/lib/python3.7/shutil.py", line 266, in copy2
    copyfile(src, dst, follow_symlinks=follow_symlinks)
  File "/usr/lib/python3.7/shutil.py", line 122, in copyfile
    copyfileobj(fsrc, fdst)
  File "/usr/lib/python3.7/shutil.py", line 79, in copyfileobj
    buf = fsrc.read(length)
KeyboardInterrupt

我真的不明白这是什么意思。你能帮我修一下吗?提前致谢。

PS:我也安装geckodriver v0.26并放在与文件相同的目录中script.py

4

1 回答 1

0

使用此命令查找 geckdriver 的正确位置

$ Which geckdriver

试试这个

path = '<your driver location>'
browser = webdriver.Firefox(executable_path=path)
于 2022-01-12T12:04:01.183 回答