我开设了一门课,作为硒驱动器的基本设置。当我运行它时,我 收到一条错误消息,称为“无效参数”,我不该做。
我认为此代码中的元组“ url”存在错误。请帮助我。
SeleniumDriver类: '''chromedriver(硒)的基本设置'''
def __init__(self,
driversource='C:\\Users\Ewis\Downloads\chromedriver.exe',
url = ('https://realpython.com/')
):
self.driversource = driversource
self.url = url # this tuple
def __enter__(self):
self.driver = webdriver.Chrome(executable_path=self.driversource)
for urls in self.url:
self.driver.get(urls)
return self.driver, Keys
def __exit__(self, exc_type, exc_val, exc_trace):
self.driver.quit()
回溯(最近通话最近一次):
File "<stdin>", line 1, in <module>
File "c:\python\progs\my_modules\seleniumdriver\seleniumdriver.py", line 16, in __enter__
resp = self.driver.get(urls)
File "C:\python\python run 3.7.3\lib\site-packages\selenium\webdriver\remote\webdriver.py", line 333, in get
self.execute(Command.GET, {'url': url})
File "C:\python\python run 3.7.3\lib\site-packages\selenium\webdriver\remote\webdriver.py", line 321, in execute
self.error_handler.check_response(response)
File "C:\python\python run 3.7.3\lib\site-packages\selenium\webdriver\remote\errorhandler.py", line 242, in check_response
raise exception_class(message, screen, stacktrace)
selenium.common.exceptions.InvalidArgumentException: Message: invalid argument
(Session info: chrome=75.0.3770.100)
答案 0 :(得分:0)
欢迎使用Stackoverflow。可能的错误是您没有将元组作为url
参数传递。正确的格式是
def __init__(self,
driversource='C:\\Users\Ewis\Downloads\chromedriver.exe',
url = ('https://realpython.com/', )
):
self.driversource = driversource
self.url = url # this tuple
在没有几乎不引人注意的逗号的情况下,您的默认url
参数很简单
带括号的字符串。