前往小程序,Get更优阅读体验!
立即前往
首页
学习
活动
专区
工具
TVP
发布
社区首页 >专栏 >selenium + firefox + webdriver 遇到的坑

selenium + firefox + webdriver 遇到的坑

作者头像
拓荒者
发布2019-03-11 11:03:22
2.9K0
发布2019-03-11 11:03:22
举报
文章被收录于专栏:运维经验分享运维经验分享

lunix中启动webdriver时报错一:

测试代码为:

代码语言:javascript
复制
  1. #!/usr/bin/python
  2. # -*- coding: utf-8 -*-
  3. from selenium import webdriver
  4. driver = webdriver.Firefox()
  5. driver.get("https://www.baidu.com")

运行报错信息如下:

代码语言:javascript
复制
  1. Traceback (most recent call last):
  2. File "maimai_web.py", line 14, in <module>
  3. driver = webdriver.Firefox()
  4. File "/usr/local/python3.6/lib/python3.6/site-packages/selenium/webdriver/firefox/webdriver.py", line 152, in __init__
  5. keep_alive=True)
  6. File "/usr/local/python3.6/lib/python3.6/site-packages/selenium/webdriver/remote/webdriver.py", line 98, in __init__
  7. self.start_session(desired_capabilities, browser_profile)
  8. File "/usr/local/python3.6/lib/python3.6/site-packages/selenium/webdriver/remote/webdriver.py", line 188, in start_session
  9. response = self.execute(Command.NEW_SESSION, parameters)
  10. File "/usr/local/python3.6/lib/python3.6/site-packages/selenium/webdriver/remote/webdriver.py", line 256, in execute
  11. self.error_handler.check_response(response)
  12. File "/usr/local/python3.6/lib/python3.6/site-packages/selenium/webdriver/remote/errorhandler.py", line 194, in check_response
  13. raise exception_class(message, screen, stacktrace)
  14. selenium.common.exceptions.WebDriverException: Message: Process unexpectedly closed with status 1

处理方法:

代码语言:javascript
复制
  1. #!/usr/bin/python
  2. # -*- coding: utf-8 -*-
  3. from pyvirtualdisplay import Display
  4. from selenium import webdriver
  5. display = Display(visible=0, size=(1920, 1080))
  6. display.start()
  7. driver = webdriver.Firefox()
  8. driver.get("https://www.baidu.com")

结果:

运行ok,搞定!

坑二、webdriver实例化报错

采用多线程调用webdriver时候,偶尔会出现这样的错:selenium.common.exceptions.WebDriverException: Message: connection refused

代码语言:javascript
复制
  1. Exception in thread Thread-2:
  2. Traceback (most recent call last):
  3. File "/usr/local/python3.6/lib/python3.6/threading.py", line 916, in _bootstrap_inner
  4. self.run()
  5. File "/usr/local/python3.6/lib/python3.6/threading.py", line 864, in run
  6. self._target(*self._args, **self._kwargs)
  7. File "maimai_tran_account_driver.py", line 591, in debug
  8. t = TrainAccount(count,lock)
  9. File "maimai_tran_account_driver.py", line 32, in __init__
  10. self.chrome = webdriver.Firefox()
  11. File "/usr/local/python3.6/lib/python3.6/site-packages/selenium/webdriver/firefox/webdriver.py", line 152, in __init__
  12. keep_alive=True)
  13. File "/usr/local/python3.6/lib/python3.6/site-packages/selenium/webdriver/remote/webdriver.py", line 98, in __init__
  14. self.start_session(desired_capabilities, browser_profile)
  15. File "/usr/local/python3.6/lib/python3.6/site-packages/selenium/webdriver/remote/webdriver.py", line 188, in start_session
  16. response = self.execute(Command.NEW_SESSION, parameters)
  17. File "/usr/local/python3.6/lib/python3.6/site-packages/selenium/webdriver/remote/webdriver.py", line 256, in execute
  18. self.error_handler.check_response(response)
  19. File "/usr/local/python3.6/lib/python3.6/site-packages/selenium/webdriver/remote/errorhandler.py", line 194, in check_response
  20. raise exception_class(message, screen, stacktrace)
  21. selenium.common.exceptions.WebDriverException: Message: connection refused

 查看geckodriver.log具体报错信息。

后续的坑继续填。。。

(adsbygoogle = window.adsbygoogle || []).push({});

本文参与 腾讯云自媒体分享计划,分享自作者个人站点/博客。
原始发表:2018/09/07 ,如有侵权请联系 cloudcommunity@tencent.com 删除

本文分享自 作者个人站点/博客 前往查看

如有侵权,请联系 cloudcommunity@tencent.com 删除。

本文参与 腾讯云自媒体分享计划  ,欢迎热爱写作的你一起参与!

评论
登录后参与评论
0 条评论
热度
最新
推荐阅读
目录
  • lunix中启动webdriver时报错一:
    • 测试代码为:
      • 运行报错信息如下:
        • 处理方法:
          • 结果:
          • 坑二、webdriver实例化报错
          领券
          问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档