Fehler meldung im Pythonscript Expected indented block

Wenn du dir nicht sicher bist, in welchem der anderen Foren du die Frage stellen sollst, dann bist du hier im Forum für allgemeine Fragen sicher richtig.
Antworten
stefan1212
User
Beiträge: 9
Registriert: Sonntag 7. Februar 2021, 14:43

Hallo,
ich bekomme folgende fehlermeldung bei meinem python code, kann mir jemand dabei helfen den fehler zu beheben ?
würde mich freuen!
LG


Visual Studio Code zeigt mir an, dass der fehler hiebei liegt
http://prntscr.com/1af56l6

Code: Alles auswählen

# Nano Bot V2

from ssl import wrap_socket
from selenium import webdriver
from webdriver_manager.chrome import ChromeDriverManager
from selenium.webdriver.common import keys
from selenium.webdriver.common import by
from selenium.webdriver.support.ui import WebDriverWait
from selenium.webdriver.support import expected_conditions as EC
from selenium.webdriver.support.select import Select
from selenium.webdriver.support.ui import Select
import random
import time
import re
from os import listdir
from os.path import isfile, join, exists
import os




ep = []
mypath ="images"
emailList = []
password = []
cities = []

ep = [f for f in listdir(mypath) if isfile(join(mypath, f))]
fullPath = os.getcwd()
ep_count = 1
city_count = 0
user_count = 0

with open('Email list.txt') as file:
  for temp in file:
    emailList.append(temp.split(",")[0])
    password.append(temp.split(",")[1].strip())
username_list = []
with open('username.txt') as file:
  for temp in file:
    if temp.strip() != '':
      username_list.append(temp.strip())

with open('700 städte deutcshlan.txt') as file:
  for temp in file:
    cities.append(temp.strip())
city_count = 0
try:
  file = open('city_count.txt')
  tmp_str = file.read()
  if tmp_str == "":
    city_count = 0
  else:
    city_count = int(tmp_str)
  file.close()
except FileNotFoundError:
    city_count = 0
try:
  file = open('user_count.txt')
  tmp_str = file.read()
  if tmp_str == "":
    user_count = 0
  else:
    user_count = int(tmp_str)
  file.close()
except FileNotFoundError:
    user_count = 0




day = ['1', '2', '3', '4', '5', '6', '7', '8', '9', '10''11', '12', '13', '14', '15', '16', '17', '18', '19', '20'
'21', '22', '23', '24', '25', '26', '27', '28', '29', '30', '31']

month = ['Januar', 'Februar', 'März', 'April', 'Mai', 'Juni','Juli', 'August', 'September', 'Oktober', 'November', 'Dezember']

year = ['1996', '1995', '1994', '1993', '1992', '1991', '1990', '1989', '1998']

height = ['155', '156', '157', '158', '159', '160']

weight = ['61', '62', '63', '64', '65', '67', '54', '55', '56', '57', '58', '59']

hair_color = ['blond', 'braun', 'schwarz', 'rot', 'grau', 'dunkelblond', 'hellbraun', 'dunkelbraun']

hair_length = ['sehrlang',  'lang', 'normal', 'kurz']

eye_color = ['blau', 'braun', 'grün', 'blaugrün', 'grünbraun']

figure = ['muskulös', 'sportlich', 'schlank', 'durchschnittlich']

# PATH = 'C:\windows\chromedriver.exe'





for i in range(len(emailList)):



  def create_account(i):
  
  global ep_count
  global city_count
  global user_count
  driver = webdriver.Chrome(ChromeDriverManager().install())
  driver.delete_all_cookies()
  driver.get('https://onlinedatingcheck.de/?goto=124')
  print(driver.title)

  

  time.sleep(1)
  try:
    driver.find_element_by_css_selector('span').click()
  except:
    pass
  time.sleep(1)
  driver.find_element_by_name('gender').send_keys('eine frau')

  driver.find_element_by_name('gender_looking_for').send_keys('M')
  

  driver.find_element_by_xpath('//*[@id="submitbutton"]').click()



  time.sleep(3)
  button = driver.find_element_by_xpath('//*[@id="step2"]/div[2]/div/button').click()
  time.sleep(2)
  
  
  driver.find_element_by_xpath('//*[@id="step3"]/div[1]/div/div[2]/div[1]/div/select').send_keys('163')
  
  driver.find_element_by_xpath('//*[@id="step3"]/div[1]/div/div[2]/div[2]/div/select').send_keys('69')
  
  driver.find_element_by_xpath('//*[@id="haircolor_female"]/div/select').send_keys('braun')
  
  driver.find_element_by_xpath('//*[@id="step3"]/div[1]/div/div[2]/div[7]/div/select').send_keys('lang')
  
  driver.find_element_by_xpath('//*[@id="eyecolor_female"]/div/select').send_keys('blau')
  
  driver.find_element_by_xpath('//*[@id="figure_female"]/div/select').send_keys('sportlich')

  driver.find_element_by_xpath('//*[@id="step3"]/div[2]/div/button').click()
  time.sleep(2)

    
  if city_count == len(cities):
    city_count = 0
  
  driver.find_element_by_xpath('//*[@id="step4"]/div[1]/div/div[2]/div/div/div[1]/div[1]/button').click()
  time.sleep(2)
  for c in cities[city_count]:
    driver.find_element_by_xpath('//*[@id="step4"]/div[1]/div/div[2]/div/div/div[1]/div[1]/div/div[1]/input').send_keys(c)
    time.sleep(1)
  city_count += 1
  time.sleep(2)
  driver.find_element_by_xpath('//*[@id="step4"]/div[1]/div/div[2]/div/div/div[1]/div[1]/div/ul/li[1]/a').click()
  time.sleep(2)
  
  Select(driver.find_element_by_name('dob_day')).select_by_visible_text(random.choice(day))
  time.sleep(2)
  Select(driver.find_element_by_name('dob_month')).select_by_visible_text(random.choice(month)) 
  time.sleep(2)
  Select(driver.find_element_by_name('dob_year')).select_by_visible_text(random.choice(year))

  driver.find_element_by_xpath('//*[@id="relationship_status_gender_female"]/div/select').send_keys('single')

  driver.find_element_by_xpath('//*[@id="step5"]/div[2]/div/button').click()
  time.sleep(2)


  emailElem = driver.find_element_by_xpath('//*[@id="step6"]/div[1]/div/div[2]/div[1]/div[1]/div/input').click()
  time.sleep(2)
  emailAdresse = driver.find_element_by_name("email").send_keys(emailList[i])

  driver.find_element_by_xpath('//*[@id="step6"]/div[1]/div/div[2]/div[1]/div[2]/div/input').clear()
  time.sleep(1)
  username = username_list[user_count]
  for c in username:
    driver.find_element_by_xpath('//*[@id="step6"]/div[1]/div/div[2]/div[1]/div[2]/div/input').send_keys(c)
    time.sleep(0.3)
  user_count = user_count + 1
  if user_count == len(username_list):
    user_count = 0

  driver.find_element_by_xpath('//*[@id="consent_crossregistration"]').click()
  time.sleep(1)

  driver.find_element_by_xpath('//*[@id="step6"]/div[3]/div/button').click()
  time.sleep(3)




  loginFlag = True
  try:
      error = driver.find_element_by_id('email-error').text
      loginFlag = False
  except:
    error = ""

  if loginFlag:
      import imaplib
      import getpass
      import email
      import datetime
      import webbrowser
      import re
      import quopri

      detach_dir = '.' # directory where to save attachments (default: current)
      # user = "kdalishakyea94am@outlook.com"
      # pwd = "mZGGN9ZyXk"
      user = emailList[i]
      pwd = password[i]
      subject_filter='Inbox'

      # connecting to the outlook imap server
      m = imaplib.IMAP4_SSL("outlook.office365.com")
      m.login(user,pwd)

      print ("logged in successfully...")

      status, messages = m.select(subject_filter)
      # print(messages)
      typ, data = m.search(None, "all")
      for num in data[0].split():
          rv, data = m.fetch(num, '(RFC822)')
          if rv != 'OK':

            print ("ERROR getting message", num)
            #return

      msg = email.message_from_string(str(data[0][1]))
      print (msg.get_payload(decode=True))
      m.close()
      m.logout()

      expr = r'a href="((http)s?:\/\/((\.)?(\w+)?(-)*)+(\/\S*)*)'
      #Nimmt erste URL von email
      msg = quopri.decodestring(str(msg))
      
      matches = re.search( expr, str(msg), re.I)
      #for uu in matches:
      url = matches[0]
      url = url.replace('a href="','').replace('"','').replace("=\\\\r\\\\n",'')
      driver.get(url)


      driver.find_element_by_xpath('//*[@id="habits-submit-btn"]').click()
      time.sleep(2)

      driver.find_element_by_xpath('//*[@id="introduction-submit"]/div[2]/div[1]/div/div/table/tbody/tr/td[1]/div/div/label[2]').click()
      time.sleep(2)

      driver.find_element_by_xpath('//*[@id="promote-submit"]').click()
      time.sleep(2)
      
      driver.find_element_by_xpath('//*[@id="skipButton"]').click()
      time.sleep(2)

      driver.find_element_by_xpath('//*[@id="dtyrd-form-onboarding"]/div[2]/div/div/table/tbody/tr/td[1]/div/div/label[2]').click()
      time.sleep(2)

      driver.find_element_by_xpath('//*[@id="endOnboarding"]').click()
      time.sleep(2)


      driver.get('https://www.casualdatingclub.de/settings')
      time.sleep(2)

      driver.find_element_by_xpath('//*[@id="settings"]/h4/a').click()
      time.sleep(2)

      driver.find_element_by_xpath('//*[@id="dtyrd-form-settings-login"]/table/tbody/tr[3]/td/input').send_keys(pwd)
      driver.find_element_by_xpath('//*[@id="dtyrd-form-settings-login"]/table/tbody/tr[4]/td/input').send_keys(pwd)

      driver.find_element_by_xpath('//*[@id="dtyrd-settings-login-save"]').click()
      time.sleep(3)



      if exists("result.txt"):
        with open("result.txt", "a") as file:
          domain = url.split("/")[4]
          domain = "https://www.casualdatingclub.de/"# + domain
          file.write(user + "," + pwd + "," + user.split("@")[0] + "," + domain + "\n")
      else:
        with open("result.txt", "w") as file:
          domain = url.split("/")[4]
          domain = "https://www.casualdatingclub.de/"# + domain
          file.write(user + "," + pwd + "," + user.split("@")[0] + "," + domain + "\n")

      ep_count += 1
      

      driver.quit()
      driver.quit()


emailList_cnt = len(emailList)
i = 0
while i < emailList_cnt:

  create_account(i)

  i = i + 1
  with open("Email list.txt", "w") as file:
    for j in range(i,emailList_cnt):
      file.write(emailList[j]+','+password[j]+'\n')
  
  with open("Use emails.txt", "a") as file:
    file.write(emailList[i-1]+','+password[i-1]+'\n')
  with open('city_count.txt', "w") as file:
    file.write(str(city_count))
    
Benutzeravatar
snafu
User
Beiträge: 6748
Registriert: Donnerstag 21. Februar 2008, 17:31
Wohnort: Gelsenkirchen

Der meckert über die fehlende Einrückung nach dem Doppelpunkt an der gezeigten Stelle. Da musst du halt die Einrückung entsprechend vornehmen.
Benutzeravatar
sparrow
User
Beiträge: 4231
Registriert: Freitag 17. April 2009, 10:28

@stefan1212: Bei dem Code liegt so viel im Augenblick, da weiß man gar nicht, wo man anfangen soll.

Auf den ersten Blick:

Verwende keine globalen Variablen.
Auf Modulebene - also uneingerückt - steht nur Code, der Importe, Klassen und Funktionen definiert.
Dateien öffnet man mit dem with-statement. Machst du manchmal - manchmal nicht.
Ganz sicher definiert man Funktionen nicht in Schleifen!
Importe gehören an den Anfang des Scripts auf Modulebene und nicht in irgendwelche Funktionen.

Wenn du global benutzt, ist dein Code kaputt.


Du solltest dir dringend noch einmal anschauen, was Funktionen sind und wie man sie benutzt.
Benutzeravatar
Max07t
User
Beiträge: 6
Registriert: Montag 21. Juni 2021, 15:23
Wohnort: Frankfurt am Main
Kontaktdaten:

Das musst du verbessern:
  • Imports immer an den Anfang des Programmes
  • Nach dem : immer Einrückungen
  • Verwende wenn es möglich ist kein global
  • Funktionen werden nicht in Schleifen definiert
LG
Sirius3
User
Beiträge: 17793
Registriert: Sonntag 21. Oktober 2012, 17:20

@stefan1212: du willst eine Fake-Datingplattform mit Fake-Profilen überfluten? Warum sollte man Dir dabei helfen?
Antworten