我正在尝试使用Selenium编写身份验证机器人程序,但遇到一个错误,无法完成代码!错误为**“AttributeError:“str”对象没有属性“start”",您可以在下面的终端**中看到代码和错误。
代码:'
class LoginBot():
def __init__(self):
#Excel reading
wb = load_workbook('seo-fast_profiles.xlsx')
sheet_ranges = wb['Work']
self.login = sheet_ranges['A2'].value
self.email = sheet_ranges['B2'].value
self.passw = sheet_ranges['C2'].value
#Optins and UserAgent
user = UserAgent()
options = webdriver.ChromeOptions()
options.add_argument(user.random)
self.browser = webdriver.Chrome(service=ChromeDriverManager().install(), options=options)
def close_browser(self):
self.browser.close()
self.browser.quit()
def login(self):
browser = self.browser
browser.get("https://seo-fast.ru/login")
time.sleep(random.randrange(1, 3))
username_input = browser.find_element(By.ID, "logusername")
username_input.clear()
username_input.send_keys(self.email)
time.sleep(1)
username_input.send_keys(Keys.ENTER)
time.sleep(2)
password_input = browser.find_element(By.ID, "logpassword")
password_input.send_keys(self.passw)
time.sleep(5)
password_input.send_keys(Keys.ENTER)
time.sleep(7)
#cookies
pickle.dump(browser.get_cookies(), open(f"{self.login}_cookies", "wb"))
self.close_browser()
def xpath_exists(self, url):
browser = self.browser
try:
browser.find_element(By.XPATH, url)
exist = True
except NoSuchElementException:
exist = False
return exist
bot = LoginBot()
bot.login()
'
错误:File "E:\Python\lib\site-packages\selenium\webdriver\chromium\webdriver.py", line 89, in __init__ self.service.start() AttributeError: 'str' object has no attribute 'start'
有人能解决吗?
1条答案
按热度按时间9lowa7mx1#
您错过了参数。它应该如下所示。
您需要导入以下库。