Quantcast
Channel: Active questions tagged selenium - Stack Overflow
Viewing all articles
Browse latest Browse all 97774

why can I not see my instagram comments postet with selenium

$
0
0

I create a python bot using selenium to login into instagram and comment on the newwest post from a user.

It all works and the bot enters the comment, clicks on post and I can see the comment on my browser field. But when I open the instagram app I can not see my comment.

Is that a security problem that instagram recognize I am using a bot and deleted all of my action after I leave the page or is the sendkeys() method only for the login usable?

This is my code:

from selenium import webdriver
import os 
import time

class InstagramBot:
    def __init__(self, username, password):
        self.username = username
        self.password = password
        self.base_url = 'https://www.instagram.com'
        self.driver = webdriver.Chrome('chromedriver.exe')

        self.login()

    def login(self):
        self.driver.get('{}/accounts/login/'.format(self.base_url))
        time.sleep(1)
        self.driver.find_element_by_name('username').send_keys(self.username)
        self.driver.find_element_by_name('password').send_keys(self.password)
        time.sleep(1)
        self.driver.find_element_by_xpath('//*[@id="react-root"]/section/main/div/article/div/div[1]/div/form/div[4]').click()
        time.sleep(4)

    def nav_user(self, user):
        self.driver.get('{}/{}/'.format(self.base_url, user))

    def comment_on_newest_photo(self, user, comment):
        self.nav_user(user)

        picture = self.driver.find_elements_by_tag_name('a')
        picture[8].click()
        time.sleep(3)

        text_field = self.driver.find_element_by_tag_name('textarea')
        text_field.click()
        time.sleep(1)
        self.driver.find_element_by_tag_name('textarea').send_keys(comment)

        self.driver.find_element_by_xpath('/html/body/div[4]/div[2]/div/article/div[2]/section[3]/div/form/button').click()

Viewing all articles
Browse latest Browse all 97774

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>