gpt4 book ai didi

python - geckodriver 没有在 ubuntu 上使用 selenium 和 django 打开 firefox

转载 作者:行者123 更新时间:2023-12-04 18:43:56 25 4
gpt4 key购买 nike

我花了一整天的时间来解决这个问题。我的 selenium 代码与 chromedriver 和 geckodriver 在 Windows 上完美配合,我需要 celery,我最好的选择是切换到我的 ubuntu 操作系统(版本 20)。应该显示抓取的数据的页面显示消息:连接被拒绝。 geckodriver 是 26 版
这是错误。

File "/home/maro/Desktop/crypto/cert/lib/python3.8/site-packages/django/core/handlers/exception.py", line 34, in inner
response = get_response(request)
File "/home/maro/Desktop/crypto/cert/lib/python3.8/site-packages/django/core/handlers/base.py", line 115, in _get_response
response = self.process_exception_by_middleware(e, request)
File "/home/maro/Desktop/crypto/cert/lib/python3.8/site-packages/django/core/handlers/base.py", line 113, in _get_response
response = wrapped_callback(request, *callback_args, **callback_kwargs)
File "/home/maro/Desktop/crypto/forex/views.py", line 80, in pricelist
driver = webdriver.Firefox(executable_path='/usr/bin/geckodriver')
File "/home/maro/Desktop/crypto/cert/lib/python3.8/site-packages/selenium/webdriver/firefox/webdriver.py", line 170, in __init__
RemoteWebDriver.__init__(
File "/home/maro/Desktop/crypto/cert/lib/python3.8/site-packages/selenium/webdriver/remote/webdriver.py", line 157, in __init__
self.start_session(capabilities, browser_profile)
File "/home/maro/Desktop/crypto/cert/lib/python3.8/site-packages/selenium/webdriver/remote/webdriver.py", line 252, in start_session
response = self.execute(Command.NEW_SESSION, parameters)
File "/home/maro/Desktop/crypto/cert/lib/python3.8/site-packages/selenium/webdriver/remote/webdriver.py", line 321, in execute
self.error_handler.check_response(response)
File "/home/maro/Desktop/crypto/cert/lib/python3.b/site-packages/selenium/webdriver/remote/errorhandler.py", line 242, in check_response
raise exception_class(message, screen, stacktrace)
selenium.common.exceptions.TimeoutException: Message: connection refused
我已将我的 Firefox 从 75 版更新到 80 版,但仍然没有变化。我已经多次更改驱动程序路径,但错误仍然保持不变。
这是我的 geckodriver 日志
1594416320001   mozrunner::runner   INFO    Running command: "/usr/bin/firefox" "-marionette" "-foreground" "-no-remote" "-profile" "/tmp/rust_mozprofileS5CJqR"
geckodriver 是可执行的,我还检查了主机以查看 localhost 是否附加到 127.0.... url,是的,它是。我完全糊涂了
这是我的观点.py
import time
import selenium
from django.shortcuts import render
from django.contrib.auth import login, authenticate, logout
from .forms import SignUpForm
from django.shortcuts import render, redirect

from selenium import webdriver
from selenium.webdriver.firefox.options import Options
from selenium.webdriver.common.by import By
def pricelist(request):
driver = webdriver.Firefox(executable_path='/usr/bin/geckodriver')
driver.get('')
data = []
while not data:


for elm in driver.find_elements(By.CSS_SELECTOR, "span[data-field=CPT]"):
if elm.text and elm.text != '-':
data.append(elm.text)


time.sleep(3)

context = {
"price": 123,
"mydata": data
}

return render(request, 'pricelist.html', context)

最佳答案

我已经让它工作了。我切换到 chromedriver,我遇到了类似的问题,发现 chromedriver 使用与我的 Django 应用程序相同的端口。我使用 python manage.py runserver 8001 将我的 Django 应用程序的端口更改为 8001

关于python - geckodriver 没有在 ubuntu 上使用 selenium 和 django 打开 firefox,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/62843069/

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