關於 python中的selenium 錯誤

      今天在學習python中的selenium時出現了一些錯誤,後來解決了,在這裏與大家分享解決方法。

代碼如下:

from selenium import webdriver
brower = webdriver.Firefox()
brower.get('https://www.taobao.com')
print(brower.page_source)
brower.close()
最初的運行結果是:

Traceback (most recent call last):
File "/home/eric/.local/lib/python3.5/site-packages/selenium/webdriver/common/service.py", line 74, in start
stdout=self.log_file, stderr=self.log_file)
File "/usr/lib/python3.5/subprocess.py", line 947, in init
restore_signals, start_new_session)
File "/usr/lib/python3.5/subprocess.py", line 1551, in _execute_child
raise child_exception_type(errno_num, err_msg)
FileNotFoundError: [Errno 2] No such file or directory: 'geckodriver'

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
File "/home/eric/PycharmProjects/untitled12/12.py", line 2, in
brower = webdriver.Firefox()
File "/home/eric/.local/lib/python3.5/site-packages/selenium/webdriver/firefox/webdriver.py", line 144, in init
self.service.start()
File "/home/eric/.local/lib/python3.5/site-packages/selenium/webdriver/common/service.py", line 81, in start
os.path.basename(self.path), self.start_error_message)
selenium.common.exceptions.WebDriverException: Message: 'geckodriver' executable needs to be in PATH.

Process finished with exit code 1

通過求助,了解到是瀏覽器缺少驅動造成的問題。也就是缺少geckodriver。

1.於是先下載驅動(https://github.com/mozilla/geckodriver/releases)(由於我是linux系統,我下載的是geckodriver-v0.18-linux64.tar.gz

2.下載完成後,打開終端

sudo tar zxvf geckodriver-v0.18.0-linux64.tar.gz
sudo mv geckodriver /usr/bin/ #移动到指定路径  
cd /usr/bin/                    #进入路径 
sudo chmod +x geckodriver        #除去权限 
3.重新啓動程序,正常運行,結果由於太長,在此就不粘貼類。

最後感謝爲我提供幫助的人。











  • 1
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值