gpt4 book ai didi

javascript - 如何解决 Python Selenium 错误 which

转载 作者:太空宇宙 更新时间:2023-11-04 06:41:38 25 4
gpt4 key购买 nike

我正在尝试使用 selenium 来处理一些使用 JavaScript 代码的网站。首先,我使用下面的简单示例

from selenium import webdriver

browser = webdriver.Firefox()

browser.get('http://www.yahoo.com')

browser.quit()

虽然这甚至不起作用。错误消息如下所示。我想我可能错过了 Selenium 或其他东西。你能给我一些启示吗?

Traceback (most recent call last):
File "/home/rnie/webdriver-tutorial-1x.py", line 3, in <module>
browser = webdriver.Firefox()
File "/usr/lib/python3.5/site-packages/selenium/webdriver/firefox/webdriver.py", line 145, in __init__
keep_alive=True)
File "/usr/lib/python3.5/site-packages/selenium/webdriver/remote/webdriver.py", line 92, in __init__
self.start_session(desired_capabilities, browser_profile)
File "/usr/lib/python3.5/site-packages/selenium/webdriver/remote/webdriver.py", line 179, in start_session
response = self.execute(Command.NEW_SESSION, capabilities)
File "/usr/lib/python3.5/site-packages/selenium/webdriver/remote/webdriver.py", line 236, in execute
self.error_handler.check_response(response)
File "/usr/lib/python3.5/site-packages/selenium/webdriver/remote/errorhandler.py", line 192, in check_response
raise exception_class(message, screen, stacktrace)
selenium.common.exceptions.WebDriverException: Message: connection refused

我检查了 “geckodriver.log”,它显示了以下错误消息:

1479623778556   geckodriver INFO    Listening on 127.0.0.1:49723
1479623778625 mozprofile::profile INFO Using profile path /tmp/rust_mozprofile.WMDGNONHQTud
1479623778628 geckodriver::marionette INFO Starting browser /usr/bin/firefox
1479623778641 geckodriver::marionette INFO Connecting to Marionette on localhost:35691
No protocol specified
Unable to init server: Could not connect: Connection refused
Error: cannot open display: :0

最佳答案

请检查路径,如果您使用的是 Linux,请查看 http://www.linuxquestions.org/questions/linux-server-73/can 't-open-display-no-protocol-specified-using-gdm-4175462031/

关于javascript - 如何解决 Python Selenium 错误 which,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/40701472/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com