Error making a loop for comments on instagram, who helps me? Python Selenium

Asked

Viewed 452 times

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

  • 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.

  • 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()

1 answer

0

So I don’t know how to solve your problem, but if you comment several times for this method on instagram it will realize that you are actually a bot and forbid you to comment, the correct way is to simulate to the maximum a human person typing.

Try that later.

for letra in arquivo.readline():
    commentArea.send_keys(letra)
    time.sleep(random.randint(3,8)/25)

I already made a bot of comments pro instagram using Selenium, in my program I stored the name of the users in a list and then in a txt file. After that the program drew three profiles from that list and commented letter by letter.

  • Yesterday I kept trying some ways and instead of taking the file lines, I put everything on a list and then it worked. Obg for the tip to simulate to the maximum a person by typing.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.