【问题标题】:Why this code get error: "Indentation Error: unindent does not match any outer indentation"为什么此代码会出错:“缩进错误:未缩进与任何外部缩进都不匹配”
【发布时间】:2019-11-17 15:31:40
【问题描述】:

我的代码门控错误:

 File "app.py", line 31
    ed = TwitterBot('Someusername', 'Password@gmail.com')
                                                        ^
IndentationError: unindent does not match any outer indentation level


i have install 
pip- selenium 
geckodriver

从硒导入网络驱动程序 从 selenium.webdriver.common.keys 导入密钥 进口时间

类 TwitterBot: def init(自我、用户名、密码): self.username = 用户名 self.password = 密码 self.bot = webdriver.Firefox()

def login(self):
    bot = self.bot
    bot.get('https://twitter.com/')
    time.sleep(3)
    email = bot.find_element_by_class_name('email-input')
    password = bot.find_element_by_name('sesssion[password]')
    email.clear()
    password.clear()
    email.send_keys(self.username)
    password.send_keys(self.password)
    password.send_keys(Keys.RETURN)
    time.sleep(3)

def like_tweet(self, hashtag):
    bot = self.bot
    bot.get = (
        'https://twitter.com/search?q=' + hashtag + '&src=typd')
    time.sleep(3)

 ed = TwitterBot('Someusername', 'Password@gmail.com') #some error
 ed.login()
 ed.like_tweet('webdevelopment')

【问题讨论】:

  • 因为它没有。出于某种原因,您将最后 3 行每行缩进 1 个空格

标签: python selenium twitter bots


【解决方案1】:

Python 严重依赖缩进,将缩进块视为 Java 中“{”和“}”之间的封闭代码。因此,当您离开该块时,返回与该块之前完全相同的缩进非常重要。在这种情况下,你不这样做。看起来好像每行以“ed”开头的都是一个空格,删除那个空格,一切都会好起来的。

【讨论】:

    猜你喜欢
    • 2017-08-12
    • 2010-12-15
    • 1970-01-01
    • 2018-02-08
    • 1970-01-01
    • 1970-01-01
    • 2012-05-07
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多