들어가기 앞서 인스타그램 좋아요 봇 사용은 인스타그램 정책상 권장하지 않는 행동입니다.
본 좋아요 봇은 순전히 Python selenium연습 삼아 만들어본 봇입니다.
사용과 이로 인한 손해는 순전히 본인 책임입니다.
"파이썬 으로 인스타그램 좋아요 봇"
Python에 대한 자료들을 찾아보던 중 파이썬 selenium을 이용하여
원격으로 크롬을 작동시킬 수 있다는 사실을 알게 되었다.
그래서 만들어 보았다.
원격으로 작동하는 인스타그램 피드 좋아요 봇
selenium 설치, 크롬 드라이버 설치
전체 코드를 보기 앞서 cmd에 아래 코드를 입력해
selenium을 설치해야 한다.
pip install selenium
크롬 드라이버 설치
1. 크롬 버전 확인
'Chrome 정보'를 클릭하여 버전을 확인
버전 확인(현재 버전: 106.0.5249.119)
크롬버전에 맞는 크롬 드라이버를 클릭
윈도우 사용자일 경우 win32.zip, mac 사용자일 경우 mac64.zip 설치.
아래 링크를 클릭 클릭하여 내 크름버전에 맞는 크롬 드라이버를 설치해준다.
https://chromedriver.chromium.org/downloads
ChromeDriver - WebDriver for Chrome - Downloads
Current Releases If you are using Chrome version 107, please download ChromeDriver 107.0.5304.18 If you are using Chrome version 106, please download ChromeDriver 106.0.5249.61 If you are using Chrome version 105, please download ChromeDriver 105.0.5195.52
chromedriver.chromium.org
전체 코드를 살펴보면
from selenium import webdriver
import inspect, os, platform, time
from selenium.webdriver.common.keys import Keys
from selenium.webdriver.common.action_chains import ActionChains
import random
def bot():
print("++++ Created by 'Kim_sehyun_34' :) ++++")
time.sleep(0.5)
print()
print("과도한 사용은 비추천 드립니다.")
time.sleep(0.5)
print()
id = input('인스타id : ')
pw = input('인스타pw : ')
tag = input('작업태그 : ')
cnt = int(input('작업횟수(숫자) : '))
ff = int(input("작업할 방법 설정(인기피드=0 , 최신피드=1) 입력:"))
if ff==0:
print("작업할 피드: 인기피드")
elif ff==1:
print("작업할 피드: 최신피드")
#CDV
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/102.0.5005.61 Safari/537.36')
current_folder = os.path.realpath(os.path.abspath(os.path.split(inspect.getfile(inspect.currentframe()))[0]))
if platform.system() == 'Windows':
driver_path = os.path.join(current_folder, 'chromedriver.exe')
else:
driver_path = os.path.join(current_folder, 'chromedriver')
driver = webdriver.Chrome(driver_path, options=options)
driver.implicitly_wait(10)
driver.get('https://www.instagram.com/?hl=ko')
print('로그인중....')
time.sleep(5)
#아이디
id_input = driver.find_element_by_xpath('//*[@id="loginForm"]/div/div[1]/div/label')
id_input.click()
id_input.send_keys(id)
#PW
pw_input = driver.find_element_by_xpath('//*[@id="loginForm"]/div/div[2]/div/label')
pw_input.click()
pw_input.send_keys(pw)
time.sleep(random.uniform(1,3))
#로그인 버튼
login_btn = driver.find_element_by_xpath('//*[@id="loginForm"]/div/div[3]/button')
login_btn.click()
time.sleep(5)
#이동
time.sleep(random.uniform(2,3))
driver.get('https://www.instagram.com/explore/tags/{}/'.format(tag))
time.sleep(5)
#최근피드 선택
if ff==1:
print("인스타 업데이트로 인하여 컴퓨터 버전은 최신피드가 보이지 않네요..")
#first_feed = driver.find_element_by_xpath('/html/body/div[1]/div/div[1]/div/div[1]/div/div/div[1]/div[1]/section/main/article/div[2]/div/div[1]/div[1]/a/div[1]/div[2]')
#first_feed.click()
#time.sleep(2)
#인기피드 선택
if ff==0:
first_feed = driver.find_element_by_xpath('/html/body/div[1]/div/div/div/div[1]/div/div/div/div[1]/section/main/article/div/div/div/div[1]/div[1]/a/div[1]/div[2]')
first_feed.click()
time.sleep(2)
for idx in range(cnt):
xpath = "//article//section/span/button"
el_list = driver.find_elements_by_xpath(xpath)
el_list[0].click()
time.sleep(1+random.random())
xpath2 = "//a"
el_list2 = driver.find_elements_by_xpath(xpath2)
time.sleep(random.uniform(1,2))
#다음
nextFeed = driver.find_element_by_xpath('/html/body/div[1]/div/div/div/div[2]/div/div/div[1]/div/div[3]/div/div/div/div/div[1]/div/div/div/button')
nextFeed.click()
time.sleep(random.uniform(3,4))
print('===========모든 작업 완료==============')
time.sleep(2)
driver.quit()
bot()
os.system('pause')
코드 분석
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/102.0.5005.61 Safari/537.36')
current_folder = os.path.realpath(os.path.abspath(os.path.split(inspect.getfile(inspect.currentframe()))[0]))
if platform.system() == 'Windows':
driver_path = os.path.join(current_folder, 'chromedriver.exe')
else:
driver_path = os.path.join(current_folder, 'chromedriver')
driver = webdriver.Chrome(driver_path, options=options)
driver.implicitly_wait(10)
selenium을 이용하여 작동 chrome작동.
id_input = driver.find_element_by_xpath('//*[@id="loginForm"]/div/div[1]/div/label')
id_input.click()
id_input.send_keys(id)
로그인 페이지에서 키보드의 F12 키를 이용하여
페이지의 HTML배열을 볼 수 있다.
이를 이용하여 사용자 이름 입력 칸의 XPath경로를 찾아낼 수 있다.
ff = int(input("작업할 방법 설정(인기피드=0 , 최신피드=1) 입력:"))
##########
if ff==0:
print("작업할 피드: 인기피드")
elif ff==1:
print("작업할 피드: 최신피드")
##########
if ff==1:
print("인스타 업데이트로 인하여 컴퓨터 버전은 최신피드가 보이지 않네요..")
#first_feed = driver.find_element_by_xpath('/html/body/div[1]/div/div[1]/div/div[1]/div/div/div[1]/div[1]/section/main/article/div[2]/div/div[1]/div[1]/a/div[1]/div[2]')
#first_feed.click()
#time.sleep(2)
#인기피드 선택
if ff==0:
first_feed = driver.find_element_by_xpath('/html/body/div[1]/div/div/div/div[1]/div/div/div/div[1]/section/main/article/div/div/div/div[1]/div[1]/a/div[1]/div[2]')
first_feed.click()
time.sleep(2)
if 절을 이용하여 인기 또는 최신 피드로 봇을 설정 가능하게 만들었다.
for idx in range(cnt):
xpath = "//article//section/span/button"
el_list = driver.find_elements_by_xpath(xpath)
el_list[0].click()
time.sleep(1+random.random())
xpath2 = "//a"
el_list2 = driver.find_elements_by_xpath(xpath2)
time.sleep(random.uniform(1,2))
#다음
nextFeed = driver.find_element_by_xpath('/html/body/div[1]/div/div/div/div[2]/div/div/div[1]/div/div[3]/div/div/div/div/div[1]/div/div/div/button')
nextFeed.click()
time.sleep(random.uniform(3,4))
메인 코드의 경우 for문을 사용하여 지정한 횟수만큼 작동하게 만들었으며,
time.sleep 에 random함수를 더하여 불규칙 적으로 작동하게 만들었다.
https://github.com/FURY312/IGB-v2.3.git
GitHub - FURY312/IGB-v2.3: Ksh python repository
Ksh python repository. Contribute to FURY312/IGB-v2.3 development by creating an account on GitHub.
github.com
^ ^ ^ 깃허브 링크 ^ ^ ^
'Python' 카테고리의 다른 글
[Python파이썬] 벤포드 법칙으로 자료의 참, 거짓 분석 (0) | 2022.10.26 |
---|---|
[파이썬Python] 문자암호화, 복호화 (암호 발생기 만들기) (0) | 2022.10.22 |
[Python파이썬] 파일검색, 파일삭제 하는 기능을 이용해서 컴퓨터 시한폭탄 만들기. (0) | 2022.10.22 |
Python파이썬 특정 지점의 RGB 값을 구하기 (0) | 2022.10.18 |
Python파이썬으로 채팅 디스코드 봇 만들기. (0) | 2022.10.17 |