0

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.

  • Please clarify your specific problem or provide additional details to highlight exactly what you need. As it's currently written, it's hard to tell exactly what you're asking. – Community Apr 06 '22 at 16:46

2 Answers2

0

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)
cruisepandey
  • 28,520
  • 6
  • 20
  • 38
  • C:\Users\HOYAO\AppData\Local\Temp/ipykernel_16264/2381267424.py:6: DeprecationWarning: firefox_profile has been deprecated, please use an Options object FireFoxProfile = webdriver.FirefoxProfile() C:\Users\HOYAO\AppData\Local\Temp/ipykernel_16264/2381267424.py:8: DeprecationWarning: executable_path has been deprecated, please pass in a Service object browser = webdriver.Firefox(executable_path=FireFoxDriverPath) These the error i get after chaging FirefoxProfile() Message: 'Geckodriver.exe' executable needs to be in PATH. – Roclusa chieng Apr 11 '22 at 10:12
0

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

undetected Selenium
  • 183,867
  • 41
  • 278
  • 352
  • C:\Users\HOYAO\AppData\Local\Temp/ipykernel_16264/2381267424.py:6: DeprecationWarning: firefox_profile has been deprecated, please use an Options object FireFoxProfile = webdriver.FirefoxProfile() C:\Users\HOYAO\AppData\Local\Temp/ipykernel_16264/2381267424.py:8: DeprecationWarning: executable_path has been deprecated, please pass in a Service object browser = webdriver.Firefox(executable_path=FireFoxDriverPath) These the error i get after chaging FirefoxProfile() Message: 'Geckodriver.exe' executable needs to be in PATH. – Roclusa chieng Apr 11 '22 at 10:09
  • @Roclusachieng Checkout the updated answer and let me know the status. – undetected Selenium Apr 11 '22 at 10:25