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_preferences("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'
CodePudding user response:
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)
CodePudding user response:
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?