无法通过Python在Firefox中打开网站

我试图通过硒python在firefox中打开一个站点,当我运行代码时,它什么也没发生后就打开了firefox,

观看此内容-> HOW TO USE FIREFOX IN PYTHON & HOW TO SET VALUES IN 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

WHEN I RUN THE CODE I GOT THIS ERR 如何在PYTHON中使用FF?

提前THX

# 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
dukx95 回答:无法通过Python在Firefox中打开网站

要设置首选项,您必须使用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不知道如何同时运行两个浏览器-这会给您错误消息。

本文链接:https://www.f2er.com/3145201.html

大家都在问