jihyunjeongme / 2019-SNS-Programming

0 stars 0 forks source link

SNS 프로그래밍 8주차 #5

Open jihyunjeongme opened 5 years ago

jihyunjeongme commented 5 years ago

from selenium import webdriver
import os
import time
import random

# ======== 1. Setting Options =======
options = webdriver.ChromeOptions()

# Chrome을 안 띄우고 수행하고 싶으면 아래 주석을 해제(리눅스 서버에서 작업시 headless 추천, 디버깅시는 headless 주석처리)
# options.add_argument("headless")

# Chrome 설정 : 진짜 유저가 작업하는 것처럼 보이도록 설정
options.add_argument("window-size=1920x1080")
options.add_argument("disable-gpu")
options.add_argument(
# user-agent
        "user-agent=Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_0) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/77.0.3865.120 Safari/537.36"
    )
options.add_argument("lang=ko_KR")

browser = webdriver.Chrome(
    os.getcwd() + "/chromedriver",
    chrome_options=options,
)

time.sleep(2 + random.random() * 1.2)

browser.get("https://instagram.com/")
time.sleep(2 + random.random() * 1.2)

# 로그인
login_link = browser.find_element_by_css_selector(
    "p.izU2O"
).find_element_by_css_selector("a")

login_link.click()

time.sleep(3 + random.random() * 1.2)
id = "id"
password = "pw"

try:
    time.sleep(3 + random.random() * 1.2)
    username_input = browser.find_elements_by_css_selector("input._2hvTZ")[0]
    username_input.send_keys(id)
    time.sleep(3 + random.random() * 1.2)
    password_input = browser.find_elements_by_css_selector("input._2hvTZ")[1]
    password_input.send_keys(password)
    time.sleep(3 + random.random() * 1.2)
    password_input.submit()

except IndexError:
    time.sleep(3 + random.random() * 1.2)
    username_input = browser.find_elements_by_css_selector("input.iQh0w")[0]
    username_input.send_keys(id)
    time.sleep(3 + random.random() * 1.2)
    password_input = browser.find_elements_by_css_selector("input.iQh0w")[1]
    password_input.send_keys(password)
    time.sleep(3 + random.random() * 1.2)
    password_input.submit()

hash_tags = ['토요일', '프로그래밍', '단풍']
for hash_tag in hash_tags:
    time.sleep(3 + random.random() * 1.2)
    browser.get("https://www.instagram.com/explore/tags/" + hash_tag)
    time.sleep(3 + random.random() * 1.2)
    element = browser.find_elements_by_css_selector("div._9AhH0")[9]
    element.click()

    count_number = 3

    for i in range(count_number):
        time.sleep(4 + random.random() * 1.2)
        like = browser.find_element_by_css_selector(
            "span.fr66n > button > span"
        )

        like.click()

        time.sleep(4.5 + random.random() * 1.3)

        browser.find_element_by_css_selector(
            "a.HBoOv.coreSpriteRightPaginationArrow"
        ).click()

        time.sleep(4 + random.random() * 1.2)

time.sleep(4 + random.random() * 1.2)
browser.close()
jihyunjeongme commented 5 years ago

from selenium import webdriver
import os
import time
import random

# ======== 1. Setting Options =======
options = webdriver.ChromeOptions()

# Chrome을 안 띄우고 수행하고 싶으면 아래 주석을 해제(리눅스 서버에서 작업시 headless 추천, 디버깅시는 headless 주석처리)
# options.add_argument("headless")

# Chrome 설정 : 진짜 유저가 작업하는 것처럼 보이도록 설정
options.add_argument("window-size=1920x1080")
options.add_argument("disable-gpu")
options.add_argument(
    # user-agent
    "user-agent=Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_0) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/77.0.3865.120 Safari/537.36"
)
options.add_argument("lang=ko_KR")

browser = webdriver.Chrome(os.getcwd() + "/chromedriver", chrome_options=options)

time.sleep(2 + random.random() * 1.2)

browser.get("https://instagram.com/")
time.sleep(2 + random.random() * 1.2)

# 로그인
login_link = browser.find_element_by_css_selector(
    "p.izU2O"
).find_element_by_css_selector("a")

login_link.click()

time.sleep(3 + random.random() * 1.2)
id = "stophyuni@gmail.com"
password = "ssss"

try:
    time.sleep(3 + random.random() * 1.2)
    username_input = browser.find_elements_by_css_selector("input._2hvTZ")[0]
    username_input.send_keys(id)
    time.sleep(3 + random.random() * 1.2)
    password_input = browser.find_elements_by_css_selector("input._2hvTZ")[1]
    password_input.send_keys(password)
    time.sleep(3 + random.random() * 1.2)
    password_input.submit()

except IndexError:
    time.sleep(3 + random.random() * 1.2)
    username_input = browser.find_elements_by_css_selector("input.iQh0w")[0]
    username_input.send_keys(id)
    time.sleep(3 + random.random() * 1.2)
    password_input = browser.find_elements_by_css_selector("input.iQh0w")[1]
    password_input.send_keys(password)
    time.sleep(3 + random.random() * 1.2)
    password_input.submit()

time.sleep(3 + random.random() * 1.2)
browser.get("https://www.instagram.com/p/B2bfHfnnRB5/")

time.sleep(3 + random.random() * 1.2)
element = browser.find_elements_by_css_selector("a.FPmhX")[3]
element.click()

time.sleep(3 + random.random() * 1.2)
element = browser.find_elements_by_css_selector("div._9AhH0")[0]
element.click()

count_number = 3

for i in range(count_number):
    time.sleep(3 + random.random() * 1.2)
    like = browser.find_element_by_css_selector("span.fr66n > button > span")
    like.click()
    time.sleep(3.5 + random.random() * 1.3)
    browser.find_element_by_css_selector(
        "a.HBoOv.coreSpriteRightPaginationArrow"
    ).click()

time.sleep(5 + random.random() * 1.2)
browser.close()
jihyunjeongme commented 5 years ago
from selenium import webdriver
import os
import time
import random

# ======== 1. Setting Options =======
options = webdriver.ChromeOptions()

# Chrome을 안 띄우고 수행하고 싶으면 아래 주석을 해제(리눅스 서버에서 작업시 headless 추천, 디버깅시는 headless 주석처리)
# options.add_argument("headless")

# Chrome 설정 : 진짜 유저가 작업하는 것처럼 보이도록 설정
options.add_argument("window-size=1920x1080")
options.add_argument("disable-gpu")
options.add_argument(
# user-agent
        "user-agent=Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_0) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/77.0.3865.120 Safari/537.36"
    )
options.add_argument("lang=ko_KR")

browser = webdriver.Chrome(
    os.getcwd() + "/chromedriver",
    chrome_options=options,
)

time.sleep(2 + random.random() * 1.2)
browser.get("https://chrome.google.com/webstore/detail/editthiscookie/fngmhnnpilhplaeedifhccceomclgfbg?hl=ko")
time.sleep(60 + random.random() * 1.2)

browser.get("https://instagram.com/")
time.sleep(2 + random.random() * 1.2)

hash_tags = ['토요일', '프로그래밍', '단풍']
for hash_tag in hash_tags:
    time.sleep(3 + random.random() * 1.2)
    browser.get("https://www.instagram.com/explore/tags/" + hash_tag)
    time.sleep(3 + random.random() * 1.2)
    element = browser.find_elements_by_css_selector("div._9AhH0")[9]
    element.click()

    count_number = 3

    for i in range(count_number):
        time.sleep(4 + random.random() * 1.2)
        like = browser.find_element_by_css_selector(
            "span.fr66n > button > span"
        )

        like.click()

        time.sleep(4.5 + random.random() * 1.3)

        browser.find_element_by_css_selector(
            "a.HBoOv.coreSpriteRightPaginationArrow"
        ).click()

        time.sleep(4 + random.random() * 1.2)

time.sleep(4 + random.random() * 1.2)
browser.close()
jihyunjeongme commented 5 years ago
from selenium import webdriver
import os
import time
import random

class InstagramAuto:

    # 크롬 브라우저 세팅
    def chrome_setting(self):
        # ======== 1. Setting Options =======
        self.options = webdriver.ChromeOptions()

        # Chrome을 안 띄우고 수행하고 싶으면 아래 주석을 해제(리눅스 서버에서 작업시 headless 추천, 디버깅시는 headless 주석처리)
        # options.add_argument("headless")

        # Chrome 설정 : 진짜 유저가 작업하는 것처럼 보이도록 설정
        self.options.add_argument("window-size=1920x1080")
        self.options.add_argument("disable-gpu")
        self.options.add_argument(
            # user-agent
            "user-agent=Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_0) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/77.0.3865.120 Safari/537.36"
        )
        self.options.add_argument("lang=ko_KR")

        self.browser = webdriver.Chrome(os.getcwd() + "/chromedriver", chrome_options=self.options)

        time.sleep(2 + random.random() * 1.2)

        self.browser.get("https://instagram.com/")
        time.sleep(2 + random.random() * 1.2)

    # 로그인
    def login_instagram(self, id, password):
        # 로그인
        login_link = self.browser.find_element_by_css_selector(
            "p.izU2O"
        ).find_element_by_css_selector("a")

        login_link.click()

        try:
            time.sleep(3 + random.random() * 1.2)
            username_input = self.browser.find_elements_by_css_selector("input._2hvTZ")[0]
            username_input.send_keys(id)
            time.sleep(3 + random.random() * 1.2)
            password_input = self.browser.find_elements_by_css_selector("input._2hvTZ")[1]
            password_input.send_keys(password)
            time.sleep(3 + random.random() * 1.2)
            password_input.submit()

        except IndexError:
            time.sleep(3 + random.random() * 1.2)
            username_input = self.browser.find_elements_by_css_selector("input.iQh0w")[0]
            username_input.send_keys(id)
            time.sleep(3 + random.random() * 1.2)
            password_input = self.browser.find_elements_by_css_selector("input.iQh0w")[1]
            password_input.send_keys(password)
            time.sleep(3 + random.random() * 1.2)
            password_input.submit()

    # 좋아요 누르기
    def liker_auto(self):
        hash_tags = ["토요일", "프로그래밍", "단풍"]
        for hash_tag in hash_tags:

            self.browser.get("https://www.instagram.com/explore/tags/" + hash_tag)

            time.sleep(3 + random.random() * 1.2)

            self.element = self.browser.find_elements_by_css_selector("div._9AhH0")[9]
            self.element.click()

            count_number = 3

            for i in range(count_number):
                time.sleep(3 + random.random() * 1.2)
                like = self.browser.find_element_by_css_selector("span.fr66n > button > span")

                like.click()
                time.sleep(3.5 + random.random() * 1.3)

                self.browser.find_element_by_css_selector(
                    "a.HBoOv.coreSpriteRightPaginationArrow"
                ).click()
                # time.sleep(3 + random.random() * 1.2)

if __name__ == "__main__":
    insta_auto = InstagramAuto()
    insta_auto.chrome_setting()
    insta_auto.login_instagram("id", "password")
    insta_auto.liker_auto()
jihyunjeongme commented 5 years ago
from selenium import webdriver
import os
import time
import random
import sys
from PyQt5.QtWidgets import QApplication, QWidget, QLabel, QLineEdit, QPushButton

class InstagramAuto(QWidget):
    def __init__(self):
        super().__init__()

        self.btn1 = QPushButton("&Like", self)

        self.lbl1 = QLabel("ID", self)
        self.lbl1.move(30, 40)

        self.lbl2 = QLabel("PW", self)
        self.lbl2.move(30, 70)

        self.lbl3 = QLabel("Tag1", self)
        self.lbl3.move(30, 100)

        self.lbl4 = QLabel("Tag2", self)
        self.lbl4.move(30, 130)

        self.lbl5 = QLabel("Tag3", self)
        self.lbl5.move(30, 160)

        # self.lbl6 = QLabel("UserName", self)
        # self.lbl6.move(30, 190)

        self.lbl7 = QLabel("LikeCount", self)
        self.lbl7.move(30, 190)

        self.qle1 = QLineEdit(self)
        self.qle1.move(100, 40)

        self.qle2 = QLineEdit(self)
        self.qle2.setEchoMode(QLineEdit.Password)

        self.qle2.move(100, 70)

        self.qle3 = QLineEdit(self)
        self.qle3.move(100, 100)

        self.qle4 = QLineEdit(self)
        self.qle4.move(100, 130)

        self.qle5 = QLineEdit(self)
        self.qle5.move(100, 160)

        # self.qle6 = QLineEdit(self)
        # self.qle6.move(100, 190)

        self.qle7 = QLineEdit(self)
        self.qle7.move(100, 190)

        # self.qle8 = QLineEdit(self)
        # self.qle8.move(100, 250)

        self.setWindowTitle("Instagram Auto Program")
        # x, y, width, height
        self.setGeometry(800, 400, 300, 260)
        self.show()

        # 버튼에 기능을 할당하는 코드
        self.btn1.clicked.connect(self.printTextEdit)
        # self.initUI()

    def printTextEdit(self):
        self.chrome_setting()

    # 크롬 브라우저 세팅
    def chrome_setting(self):
        # ======== 1. Setting Options =======
        self.options = webdriver.ChromeOptions()

        # Chrome을 안 띄우고 수행하고 싶으면 아래 주석을 해제(리눅스 서버에서 작업시 headless 추천, 디버깅시는 headless 주석처리)
        # options.add_argument("headless")

        # Chrome 설정 : 진짜 유저가 작업하는 것처럼 보이도록 설정
        self.options.add_argument("window-size=1920x1080")
        self.options.add_argument("disable-gpu")
        self.options.add_argument(
            # user-agent
            "user-agent=Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_0) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/77.0.3865.120 Safari/537.36"
        )
        self.options.add_argument("lang=ko_KR")

        self.browser = webdriver.Chrome(os.getcwd() + "/chromedriver", chrome_options=self.options)

        time.sleep(2 + random.random() * 1.2)

        self.browser.get("https://instagram.com/")
        time.sleep(2 + random.random() * 1.2)
        self.login_instagram()

    # 로그인
    def login_instagram(self):

        # 로그인
        login_link = self.browser.find_element_by_css_selector(
            "p.izU2O"
        ).find_element_by_css_selector("a")

        login_link.click()

        id = self.qle1.text()
        password = self.qle2.text()

        try:
            time.sleep(3 + random.random() * 1.2)
            username_input = self.browser.find_elements_by_css_selector("input._2hvTZ")[0]
            username_input.send_keys(id)
            time.sleep(3 + random.random() * 1.2)
            password_input = self.browser.find_elements_by_css_selector("input._2hvTZ")[1]
            password_input.send_keys(password)
            time.sleep(3 + random.random() * 1.2)
            password_input.submit()

        except IndexError:
            time.sleep(3 + random.random() * 1.2)
            username_input = self.browser.find_elements_by_css_selector("input.iQh0w")[0]
            username_input.send_keys(id)
            time.sleep(3 + random.random() * 1.2)
            password_input = self.browser.find_elements_by_css_selector("input.iQh0w")[1]
            password_input.send_keys(password)
            time.sleep(3 + random.random() * 1.2)
            password_input.submit()

        self.liker_auto()

    # 좋아요 누르기
    def liker_auto(self):
        time.sleep(3 + random.random() * 1.2)

        hash_tags = [self.qle3.text(), self.qle4.text(), self.qle5.text()]
        for hash_tag in hash_tags:

            self.browser.get("https://www.instagram.com/explore/tags/" + hash_tag)

            time.sleep(3 + random.random() * 1.2)

            self.element = self.browser.find_elements_by_css_selector("div._9AhH0")[9]
            self.element.click()

            count_number = int(self.qle7.text())

            for i in range(count_number):
                time.sleep(3 + random.random() * 1.2)
                like = self.browser.find_element_by_css_selector("span.fr66n > button > span")

                like.click()
                time.sleep(3.5 + random.random() * 1.3)

                self.browser.find_element_by_css_selector(
                    "a.HBoOv.coreSpriteRightPaginationArrow"
                ).click()
                # time.sleep(3 + random.random() * 1.2)
        self.browser.quit()

if __name__ == "__main__":
    app = QApplication(sys.argv)
    w = InstagramAuto()
    sys.exit(app.exec_())