0
I need to make a loop that picks up line by line from a file. txt and post as comment on instagram. Through a test I managed to print the first 10 lines of a file. txt
arquivo = open('UsersFinal.txt', 'r')
linha = 0
while linha <= 10:
print(arquivo.readline())
linha = linha + 1
print('FIM')
arquivo.close
But when I went to try to comment he would only comment on the first line and then stop. Someone could help me?
A part of the code:
arquivo = open('teste.txt', 'r')
linha = 0
while linha <= 4:
commentArea = driver.find_element_by_class_name('Ypffh')
commentArea.click()
time.sleep(4)
commentArea = driver.find_element_by_class_name('Ypffh')
commentArea.click()
time.sleep(2)
commentArea.send_keys(arquivo.readline())
time.sleep(1)
publicar_button = driver.find_element_by_xpath("//button[@class='sqdOP yWX7d y3zKF ']")
publicar_button.click()
time.sleep(5)
linha = linha + 1
print('FIM!')
arquivo.close
in your txt it only has the names that will be cited in the post? Example: @usuario1 @usuario2
– edufgimenez
Yes. But yesterday I kept trying some ways and instead of taking the file lines, I put everything in a list and then it worked.
– Gabriel Prudêncio
I was going to suggest this to you, because I already did it in a project and it was the best thing, to move to a list, something else, you can reduce your code there, you’re asking him to double click on the "('Ypffh')" field and to the button you can use xpath
driver.find_element_by_xpath("//button[@type='submit']").click()
– edufgimenez