module 'selenium.webdriver' has no attribute 'firefoxprofile'

582 views Asked by At

I'm doing web scraping using selenium.I have encountered an issue.

Python version 3.9.7, window 10

Code:

url=['https://www.tradingview.com/markets/stocks-usa/market-movers-large-cap/']

catergories=['Overview','Xperformance','Valuation','Dividends','Margins','Income Statement','Balance Sheet','Oscillator','Trend-Following']

user_agent= 'Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:87.0)Gecko/20100101 Firefox/87.0'

FireFoxDriverPath = os.path.join(os.getcwd(),'Drivers','Geckodriver.exe')

FireFoxProfile = webdriver.FirefoxProfile()

FireFoxProfile.set_preference("general.useragent.override",user_agent)

browser = webdriver.Firefox(executable_path=FireFoxDriverPath)

browser.implicitly_wait(7)

url= 'https://www.tradingview.com/markets/stocks-usa/market-movers-large-cap/'

browser.get(url)

Error:

module 'selenium.webdriver' has no attribute 'firefoxprofile'

These the new error i got after i change the FirefoxProfile() Message: 'Geckodriver.exe' executable needs to be in PATH.

2

There are 2 answers

1
cruisepandey On

to able to use FirefoxProfile

You could do

from selenium.webdriver import FirefoxProfile
profile = FirefoxProfile()

and set_preference like below:

profile.set_preferences("general.useragent.override", user_agent)
2
undetected Selenium On

This error message...

module 'selenium.webdriver' has no attribute 'firefoxprofile'

...implies that selenium.webdriver has no such attribute as firefoxprofile

Instead of firefoxprofile() it should have been FirefoxProfile(). Effectively your line of code should have been:

based code block

from selenium import webdriver

user_agent= 'Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:87.0)Gecko/20100101 Firefox/87.0'
FireFoxDriverPath = os.path.join(os.getcwd(),'Drivers','Geckodriver.exe')
firefoxprofile = webdriver.FirefoxProfile()
firefoxprofile.set_preferences("general.useragent.override", user_agent)

browser = webdriver.Firefox(firefox_profile=firefoxprofile, executable_path=FireFoxDriverPath)

You can find a relevant discussion in webdriver.FirefoxProfile(): Is it possible to use a profile without making a copy of it?


Update

With FirefoxProfile() have been Deprecated and with to use a custom profile you have to use an instance of Options.

You can find a relevant discussion in DeprecationWarning: firefox_profile has been deprecated, please pass in an Options object