Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Some changes according to the new version #71

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 11 additions & 10 deletions 2021/1-2021/python-automation/bot.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
from secrets import pw
from selenium.webdriver.common.keys import Keys
from random import randint
from selenium.webdriver.common.by import By

class Bot():

Expand All @@ -20,21 +21,21 @@ def login(self, username, password):
self.driver = webdriver.Chrome()
self.driver.get('https://instagram.com/')
sleep(5)
username_input = self.driver.find_element_by_xpath('//*[@id="loginForm"]/div/div[1]/div/label/input')
username_input = self.driver.find_element("xpath",'//*[@id="loginForm"]/div/div[1]/div/label/input')
username_input.send_keys(username)
sleep(1)
password_input = self.driver.find_element_by_xpath('//*[@id="loginForm"]/div/div[2]/div/label/input')
password_input = self.driver.find_element("xpath",'//*[@id="loginForm"]/div/div[2]/div/label/input')
password_input.send_keys(password)
sleep(1)
self.driver.find_element_by_xpath('//*[@id="loginForm"]/div/div[3]/button').click()
self.driver.find_element("xpath",'//*[@id="loginForm"]/div/div[3]/button').click()
sleep(3)
self.driver.find_element_by_xpath("//button[contains(text(), 'Not Now')]").click() # clicking 'not now btn'
self.driver.find_element("xpath","//button[contains(text(), 'Not Now')]").click() # clicking 'not now btn'
sleep(2)
self.driver.find_element_by_xpath("//button[contains(text(), 'Not Now')]").click() # clicking 'not now btn'
self.driver.find_element("xpath","//button[contains(text(), 'Not Now')]").click() # clicking 'not now btn'

def like_comment_by_hashtag(self, hashtag):
self.driver.get('https://www.instagram.com/explore/tags/{}/'.format(hashtag))
links = self.driver.find_elements_by_tag_name('a')
links = self.driver.find_element(By.TAG_NAME,'a')

def condition(link):
return '.com/p/' in link.get_attribute('href')
Expand All @@ -49,20 +50,20 @@ def condition(link):
self.driver.get(link)
# like
sleep(3)
self.driver.find_element_by_xpath('//*[@id="react-root"]/section/main/div/div[1]/article/div[3]/section[1]/span[1]/button').click()
self.driver.find_element("xpath",'//*[@id="react-root"]/section/main/div/div[1]/article/div[3]/section[1]/span[1]/button').click()
sleep(5)

# comment
self.driver.find_element_by_class_name('RxpZH').click()
sleep(1)
self.driver.find_element_by_xpath("//textarea[@placeholder='Add a comment…']").send_keys(self.comments[randint(0,1)])
self.driver.find_element("xpath","//textarea[@placeholder='Add a comment…']").send_keys(self.comments[randint(0,1)])
sleep(1)
self.driver.find_element_by_xpath("//button[@type='submit']").click()
self.driver.find_element("xpath","//button[@type='submit']").click()

def main():
while True:
my_bot = Bot()
sleep(60*60) # one hour

if __name__ == '__main__':
main()
main()