title: Python writing on wrong row
body: <p>I'm coding a <strong>scraper</strong> that send some client codes to a page, and If the code Is right It must write on the sheet some info of the page that will load. If the client code is wrong, then It must go to the next code on the sheet.</p>
  <p>The same sheet send and receive the info. The client codes are on the first column and each one have It's own row to get the info.</p>
  <p>The problem is that if the client code is wrong, the code is not ignoring that row when writing the info that get on the page previously. So in the end I get all the info written on sequenced rows (2, 3, 4, 5....) without skip none of them (witch should have be skipped if the client code does not returns any info).</p>
  <p>k_bot.py</p>
  <pre><code>def search_cpfs(self):
  
      # SEARCH THROUGH THE LIST OF CLIENT CODES (1ST COLUMN OF THE SPREADSHEET), AND OBTAIN THESE INFO
      nomes = []
      idades = []
      beneficios = []
      concessoes = []
      salarios = []
      bancoss = []
      bancoscard = []
      consigs = []
      cards = []
  
      for cpf in self.cpfs:
          print(f&quot;Procurando {cpf}.&quot;)
          self.driver.get(self.bot_url)
  
          #IF THE CLIENT CODE IS RIGHT
          try:
              cpf_input = self.driver.find_element_by_xpath('//*[@id=&quot;search&quot;]/div/div[1]/input')
              cpf_input.send_keys(cpf)
  
              cpfButton = self.driver.find_element_by_xpath('//*[@id=&quot;search&quot;]/div/div[2]/button')
              cpfButton.click()
  
              time.sleep(2)
  
              self.delay = 2  # seconds
  
              nome = self.driver.find_element_by_xpath(
                  &quot;/html/body/main[1]/div[1]/div[1]/div[1]/div[1]/h2&quot;).text
              idade = self.driver.find_element_by_xpath(
                  &quot;/html/body/main[1]/div[1]/div[1]/div[1]/div[1]/ul/li[2]&quot;).text
              age = re.search(r'\((.*?)Anos', idade).group(1)
              beneficio = self.driver.find_element_by_xpath(
                  &quot;/html/body/main[1]/div[1]/div[1]/div[1]/div[2]/div[5]/span/b&quot;).text
              concessao = self.driver.find_element_by_xpath(
                  &quot;/html/body/main[1]/div[1]/div[1]/div[1]/div[2]/div[2]/span&quot;).text
              salario = self.driver.find_element_by_xpath(
                  &quot;/html/body/main[1]/div[1]/div[2]/div/div[3]/div[1]/div[1]/span&quot;).text
              bancos = self.driver.find_element_by_xpath('//*[@id=&quot;loans&quot;]').text
              bancosw = re.findall(r'(?&lt;=Banco )(\w+)', bancos)
              bankslist = ', '.join(bancosw)
              bancocard = self.driver.find_element_by_xpath('//*[@id=&quot;cards&quot;]').text
              bcardw = re.findall(r'(?&lt;=Banco )(\w+)', bancocard)
              bcardlist = ', '.join(bcardw)
              consig = self.driver.find_element_by_xpath(
                  &quot;/html/body/main[1]/div[1]/div[1]/div[3]/div[2]/span&quot;).text
              card = self.driver.find_element_by_xpath(
                  &quot;/html/body/main[1]/div[1]/div[1]/div[3]/div[3]/span&quot;).text
  
              print('CPF Valido')
              print(nome, age, beneficio, concessao, salario, bankslist, bcardlist, consig, card)
  
          # IF THE CLIENT CODE IS WRONG
          except (NoSuchElementException, UnexpectedAlertPresentException):
              print('CPF Invalido')
              continue
  
          nomes.append(nome)
          idades.append(age)
          beneficios.append(beneficio)
          concessoes.append(concessao)
          salarios.append(salario)
          bancoss.append(bankslist)
          bancoscard.append(bcardlist)
          consigs.append(consig)
          cards.append(card)
  
      return nomes, idades, beneficios, concessoes, salarios, bancoss, bancoscard, consigs, cards
  </code></pre>
  <p>cpf_updater.py</p>
  <pre><code>class CpfSearch(object):
      def __init__(self, spreadsheet_name):
          self.cpf_col = 1
          self.nome_col = 2
          self.age_col = 3
          self.beneficio_col = 4
          self.concessao_col = 5
          self.salario_col = 6
          self.bancos_col = 7
          self.bancocard_col = 8
          self.consig_col = 9
          self.card_col = 15
  
          scope = ['https://www.googleapis.com/auth/spreadsheets',
                   'https://www.googleapis.com/auth/drive.readonly']
  
          creds = ServiceAccountCredentials.from_json_keyfile_name('CONSULTAS.json', scope)
  
          client = gspread.authorize(creds)
  
          self.sheet = client.open(spreadsheet_name).sheet1
  
      def process_cpf_list(self):
  
          # SKIP OVER COLUMN HEADING IN THE SPREADSHEET
          cpfs = self.sheet.col_values(self.cpf_col)[1:]
  
          bot_url = BOT(cpfs)
          nomes, idades, beneficios, concessoes, salarios, bancoss, bancoscard, consigs, cards = bot_url.search_cpfs()
  
          # UPDATE THE SHEET
          print(&quot;Atualizando...&quot;)
  
          for cpfs in range(len(nomes)):
              self.sheet.update_cell(cpfs + 2, self.nome_col, nomes[cpfs])
              self.sheet.update_cell(cpfs + 2, self.age_col, idades[cpfs])
              self.sheet.update_cell(cpfs + 2, self.beneficio_col, beneficios[cpfs])
              self.sheet.update_cell(cpfs + 2, self.concessao_col, concessoes[cpfs])
              self.sheet.update_cell(cpfs + 2, self.salario_col, salarios[cpfs])
              self.sheet.update_cell(cpfs + 2, self.bancos_col, bancoss[cpfs])
              self.sheet.update_cell(cpfs + 2, self.bancocard_col, bancoscard[cpfs])
              self.sheet.update_cell(cpfs + 2, self.consig_col, consigs[cpfs])
              self.sheet.update_cell(cpfs + 2, self.card_col, cards[cpfs])
  
  
  cpf_updater = CpfSearch('TESTE')
  cpf_updater.process_cpf_list()
  </code></pre>