인스타그램 봇
from lib2to3.pgen2 import driver
from random import randint
from selenium import webdriver
import inspect, os, platform, time
from selenium.webdriver.common.keys import Keys
from selenium.webdriver.common.action_chains import ActionChains
instaId = input('인스타그램 아이디: ')
instaPw = input('인스타그램 패스워드: ')
instaTag = input('작업할 해쉬태그: ')
instaCnt = int(input('작업횟수(숫자만): '))
comments = ['안녕하세요', '좋은 하루 보내세요', '선팔하고갑니다', '맛있겠네요', '잘 구경하고갑니다']
options = webdriver.ChromeOptions()
options.add_argument('--disable-gpu')
options.add_argument('user-agent=Mozilla/5.0 (Windows NT 6.3; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/99.0.4841.51 Safari/537.36')
currentFolder = os.path.realpath(os.path.abspath(os.path.split(inspect.getfile(inspect.currentframe()))[0]))
//driver가 있는 경로 찾아주기
if platform.system() == "Windows":
driverPath = os.path.join(currentFolder, 'chromedriver99.exe')
else:
driverPath = os.path.join(currentFolder, 'chromedriver99')
driver = webdriver.Chrome(driverPath, options=options)
driver.implicitly_wait(10)
driver.get('https://www.instagram.com/')
print('로그인중...')
time.sleep(3)
idInput = driver.find_element_by_xpath('//*[@id="loginForm"]/div/div[1]/div/label/input')
idInput.click()
idInput.send_keys(instaId)
pwInput = driver.find_element_by_xpath('//*[@id="loginForm"]/div/div[2]/div/label/input')
pwInput.click()
pwInput.send_keys(instaPw)
loginBtn = driver.find_element_by_xpath('//*[@id="loginForm"]/div/div[3]')
loginBtn.click()
time.sleep(3)
driver.get('https://www.instagram.com/explore/tags/{}/'.format(instaTag))
time.sleep(2)
firstFeed = driver.find_element_by_xpath('//*[@id="react-root"]/section/main/article/div[1]/div/div/div[1]/div[1]/a/div/div[2]')
firstFeed.click()
time.sleep(1)
for idx in range(instaCnt):
comment = comments[randint(0, (len(comments)-1))]
//랜덤값을 comment 리스트의 인덱스로 넣어주기
div = driver.find_element_by_xpath('//*[@id="react-root"]/section/main/article/div[2]/div/div[1]/div[1]/a/div/div[2]')
div = driver.find_element_by_xpath('//*[@id="react-root"]/section/main/article/div[2]/div/div[2]/div[1]/a/div[1]/div[2]')
likeBtn = driver.find_element_by_xpath('/html/body/div[6]/div[3]/div/article/div/div[2]/div/div/div[2]/section[1]/span[1]/button')
likeBtn.click()
print('{}번째 피드 좋아요 작업 완료'.format(idx + 1))
time.sleep(2)
followBtn = driver.find_element_by_xpath('/html/body/div[6]/div[3]/div/article/div/div[2]/div/div/div[1]/div/header/div[2]/div[1]/div[2]/button')
followBtn.click()
print('{}번째 피드 팔로우 작업 완료'.format(idx + 1))
time.sleep(3)
ac = ActionChains(driver)
ac.move_to_element(driver.find_element_by_xpath('/html/body/div[6]/div[3]/div/article/div/div[2]/div/div/div[2]/section[1]/span[2]/button'))
ac.click()
ac.pause(3)
ac.send_keys(comment)
ac.pause(1)
ac.send_keys(Keys.ENTER)
ac.perform()
if idx < instaCnt:
nextFeed = driver.find_element_by_css_selector('body > div.RnEpo._Yhr4 > div.Z2Inc._7c9RR > div > div.l8mY4.feth3 > button')
nextFeed.click()
print('모든 작업 완료')
driver.quit()
Author And Source
이 문제에 관하여(인스타그램 봇), 우리는 이곳에서 더 많은 자료를 발견하고 링크를 클릭하여 보았다 https://velog.io/@yuhwan/인스타그램-봇저자 귀속: 원작자 정보가 원작자 URL에 포함되어 있으며 저작권은 원작자 소유입니다.
우수한 개발자 콘텐츠 발견에 전념 (Collection and Share based on the CC Protocol.)