Reputation: 1
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.
Upvotes: 0
Views: 743
Reputation: 193098
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:
selenium3 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?
With selenium4 FirefoxProfile()
have been Deprecated and with selenium4 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
Upvotes: 0
Reputation: 29362
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)
Upvotes: 0