[英]module 'selenium.webdriver' has no attribute 'firefoxprofile'
我正在使用 selenium 进行 web 抓取。我遇到了一个问题。
Python version 3.9.7, window 10
代码:
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)
错误:
module 'selenium.webdriver' has no attribute 'firefoxprofile'
这些是我在更改 FirefoxProfile() 消息后遇到的新错误:“Geckodriver.exe”可执行文件需要位于 PATH 中。
能够使用FirefoxProfile
你可以做
from selenium.webdriver import FirefoxProfile
profile = FirefoxProfile()
和set_preference
如下所示:
profile.set_preferences("general.useragent.override", user_agent)
这个错误信息...
module 'selenium.webdriver' has no attribute 'firefoxprofile'
...暗示selenium.webdriver
没有firefoxprofile这样的属性
而不是firefoxprofile()
它应该是FirefoxProfile() 。 实际上,您的代码行应该是:
基于selenium3的代码块
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)
您可以在webdriver.FirefoxProfile() 中找到相关讨论:Is it possible to use a profile without makes a copy of it?
使用selenium4 FirefoxProfile()
已被弃用,使用selenium4使用自定义配置文件你必须使用Options
的实例。
可以在DeprecationWarning找到相关讨论:firefox_profile has been deprecated, please pass in an Options object
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.