Не удалось открыть сайт в Firefox через Python - PullRequest
0 голосов
/ 07 ноября 2019

Я пытался открыть сайт в Firefox через Селен Python, когда я запускаю код, он открывает Firefox после того, как ничего не происходит,

СМОТРИТЕ ЭТО -> КАК ИСПОЛЬЗОВАТЬ FIREFOX В PYTHON & HOWУСТАНОВИТЬ ЗНАЧЕНИЯ В DROP-DOWN LISTS?

здесь ошибка

  bash-3.1$ C:/Users/user/AppData/Local/Programs/Python/Python35-32/python.exe d:/PYTHONS/EXTRACT-NEWS/FFD
RIVER.py
Traceback (most recent call last):
  File "d:/PYTHONS/EXTRACT-NEWS/FFDRIVER.py", line 23, in <module>
    executable_path=r"D:\\PYTHONS\\DRIVERS\\geckodriver.exe")
  File "c:\Users\user\AppData\Local\Programs\Python\Python35-32\lib\site-packages\selenium\webdriver\firefox\webdriver.py", line 174, in __init__
    keep_alive=True)
  File "c:\Users\user\AppData\Local\Programs\Python\Python35-32\lib\site-packages\selenium\webdriver\remote\webdriver.py", line 157, in __init__
    self.start_session(capabilities, browser_profile)
  File "c:\Users\user\AppData\Local\Programs\Python\Python35-32\lib\site-packages\selenium\webdriver\remote\webdriver.py", line 252, in start_session
    response = self.execute(Command.NEW_SESSION, parameters)
  File "c:\Users\user\AppData\Local\Programs\Python\Python35-32\lib\site-packages\selenium\webdriver\remote\webdriver.py", line 321, in execute
    self.error_handler.check_response(response)
  File "c:\Users\user\AppData\Local\Programs\Python\Python35-32\lib\site-packages\selenium\webdriver\remote\errorhandler.py", line 242, in check_response
    raise exception_class(message, screen, stacktrace)
selenium.common.exceptions.WebDriverException: Message: newSession

КОГДА Я ЗАПУСКАЮ КОД, Я ПОЛУЧИЛ ЭТУ ОШИБКУ КАК ИСПОЛЬЗОВАТЬ FFВ Питоне?

THX IN ADVANCE

# Import Libraries
import os
import sys
import time

from selenium import webdriver
import selenium.webdriver.firefox.options


from selenium.common.exceptions import TimeoutException

from selenium.webdriver.support.ui import WebDriverWait

from selenium.webdriver.common.by import By

from selenium.webdriver.support import expected_conditions as EC


# Configure Firefox Options
profile = webdriver.Firefox(
    executable_path=r"D:\\PYTHONS\\DRIVERS\\geckodriver.exe")
# 0 means to download to the desktop, 1 means to download to the default "Downloads" directory, 2 means to use the directory

profile.set_preference("browser.download.folderList", 2)

profile.set_preference("browser.download.dir", download_path)

profile.set_preference("browser.download.manager.showWhenStarting", False)

profile.set_preference(
    "browser.helperApps.neverAsk.saveToDisk", "application/x-gzip/text/csv")

os.system("cls")

#  firefox_profile=profile

driver = webdriver.Firefox(firefox_profile=profile)

driver.get('https://www.google.com')

print(driver.title)

# driver.quit()


  [1]: https://i.stack.imgur.com/T3Bf8.png

1 Ответ

0 голосов
/ 07 ноября 2019

Чтобы установить предпочтения, вы должны использовать FirefoxProfile() вместо Firefox()

from selenium import webdriver

profile = webdriver.FirefoxProfile()

profile.set_preference("browser.download.folderList", 2)
profile.set_preference("browser.download.dir", '.')
profile.set_preference("browser.download.manager.showWhenStarting", False)
profile.set_preference("browser.helperApps.neverAsk.saveToDisk", "application/x-gzip/text/csv")

driver = webdriver.Firefox(firefox_profile=profile, executable_path="D:\\PYTHONS\\DRIVERS\\geckodriver.exe")

driver.get('https://www.google.com')

print(driver.title)

Кстати: и не запускать webdriver.Firefox() два раза, потому что Selenium не знает, как запустить два браузерав то же время - и это выдало вам сообщение об ошибке.

Добро пожаловать на сайт PullRequest, где вы можете задавать вопросы и получать ответы от других членов сообщества.
...