这是我的 Twitter 机器人项目的代码。
from selenium import webdriver
from selenium.webdriver.common.keys import Keys
import time
class TwitterBot:
def __init__(self,username, password, search_text):
self.driver = webdriver.Chrome()
self.driver.get("https://twitter.com/home?lang=en")
time.sleep(2)
# Enter your username
self.driver.find_element_by_xpath('//*[@id="react-root"]/div/div/div[2]/main/div/div/div[1]/form/div/div[1]/label/div/div[2]/div/input')\
.send_keys(username)
# Enter your password
self.driver.find_element_by_xpath('//*[@id="react-root"]/div/div/div[2]/main/div/div/div[1]/form/div/div[2]/label/div/div[2]/div/input') \
.send_keys(password)
self.driver.find_element_by_xpath('/html/body/div/div/div/div[2]/main/div/div/div[1]/form/div/div[3]/div/div')\
.click()
time.sleep(3)
# Enter text in the search box
self.driver.find_element_by_xpath('//*[@id="react-root"]/div/div/div[2]/main/div/div/div/div[2]/div/div[2]/div/div/div/div[1]/div/div/div/form/div[1]/div/div/div[2]/input')\
.send_keys(search_text)
search_text.send_keys(Keys.ENTER)
time.sleep(4)
while True:
pass
TwitterBot("rmail@gmail.com", "abcd1234", "lamborghini")
当我尝试运行此脚本时,出现 AttributeError。
File "C:\Users\Praneeth Ravuri\PycharmProjects\Twitter Bots\Open Twitter Bots .py", line 24, in __init__
search_text.send_keys(Keys.ENTER)
AttributeError: 'str' object has no attribute 'send_keys'
有人可以解决我的问题并编辑这段代码吗?
MYYA
森栏
阿晨1998
相关分类