AI 블로그 수익화 챌린지

AI 블로그 수익화 챌린지 따라하기-2 (자동완강-PC)

aiboom 2025. 7. 23. 06:01

 

윈도우(Windows) 를 사용하는 분들을 위해서 자동으로 강의 완강을 진행할 수 있는 방법을 소개해드리도록 하겠습니다.

파이썬을 사용해서 좌표를 사용한 클릭, 이미지를 사용한 클릭 2가지 방식이 있습니다.

해당 내용을 학습 후에는 직장에서 응용해서 활용하실수 있을 겁니다.

 

3편에서는 5분에 하루 3개의 포스팅을 완료하는 방법에 대해서 알아보겠습니다.

 

챌린지이다보니 급한마음에 조급해하지 않도록 1주차 미션을 빠르게 완료하는 법 부터 알려드리고 있습니다.

3편까지 따라가서 미션을 완료한 이후에는 강의를 다시 보면서  제대로 강의를 시작해보시길 바랍니다.

 

 

 

 

(1) 파이썬 설치

 

1. 파이썬 사이트 이동 

https://www.python.org/

 

2. Downloads 선택 > Python 3.13.5 선택 (버전은 상관없음, 2025.07.23.기준)

3.  다운르드 받은 python-3.13.5-amd64.exe 더블클릭

 

4. Install Python 3.13.5(64-bit)
- Use admin privileges when installing py.exe 체크
- Add python.exe to PATH 체크

 

5. Customize installation 선택 > Next

 

6. Optional Features >  Next

6. Advanced Options > Customize install location 변경

- C:\Users\사용자명\AppData\Local\Programs\Python\Python313 => C:\Python\Python313

7. Install

8. PC 재부팅 (추천)

(2) VSCode 설치

1. VSCode 사이트 이동 

https://code.visualstudio.com/

 

2. Download for Windows 클릭

 

3. 다운받은 exe 실행

 

 

4. 동의합니다 선택 >  다음

 

5. 설치위치선택 화면 > 다음

6. 시작메뉴폴더선택 > 다음

 

7. 추가작업선택 > 다음 > 설치 > 종료

 

 

(3) VSCode 설정

 

1. VSCode 실행화면 > Mark Done  클릭

 

2. Extensions 클릭 > Korean 검색 > Korean Language Pack for Visual Studio Code  Install

 

3. VSCode 재시작 (한국어로보임)

 

 

 

4. 확장(Extensions) 클릭 >   Python 검색 > Python 설치

 

 

 

5. 바탕화면에서 마우스 우클릭 > 새로 만들기 > 폴더 >  workspace로 폴더이름 생성

 

 

 

6. VSCode 왼쪽 상단 > 파일 > 폴더열기 > 바탕화면의 workspace 선택> 폴더선택 클릭

 

 

 

7. 팝업 예, 작성자를 신뢰합니다. 클릭

 

8. VSCode왼쪽상단 >   파일 > 새파일 > test.py 입력후 엔터 > 파일생성 클릭

 

(3) 파이썬 테스트 

 

1. test.py 클릭

 

 

2. 아래의 스크립트 복사 >  test.py에 붙여넣기

 

import pyautogui
import time
# 2초 대기 후 (100, 200) 좌표로 이동해서 클릭
time.sleep(2)
pyautogui.moveTo(100, 200)
pyautogui.click()

 

3. 저장 (Ctrl + S) 또는 파일 > 저장 

- 저장을 누르면 동그라미가 사라지고 x표시가 보임

 

 

 

4. VSCode에 왼쪽상단 터미널 > 새 터미널 클릭

5. 터미널에서 python --version 입력후 엔터 ( Python 3.13.5 가 나오면 성공)

6. 터미널에서 pip install pyautogui 입력후 엔터

 

 

7. 설치가 성공한 경우 test.py 파일을 선택 > 키보드에서 F5 버튼 클릭

 

8. Python Debugger 선택 > Python 파일 선택

 

 

 

9. 파이썬이 실행되고 마우스가 해당 위치로 이동하면 작업준비 완료

 

10. 해당 내용이 좌표이동후 클릭이므로 이걸 활용해서 자동완강 가능

 

 

(4) 자동완강 실행 ( 이미지 감지해서 클릭)

* 실제 생성한 파일 (필요시 다운로드): https://github.com/oseongryu/auto-lecture

 

1. lecture.py 파일 생성

 

2. 터미널을 열고 아래 스크립트실행

 

pip install pyautogui pyscreeze pillow selenium webdriver-manager opencv-python

 

 

3. 강의 화면에서 다음으로 빨간 버튼을 1.png, 재생버튼(왼쪽하단)을 2.png 이미지로 캡쳐해서 저장

(이미지는 화면해상도에 따라 인식이 안될수 있으므로, 직접캡쳐해서 넣기)

 

1.png

 

2.png

 

 

4. 아래 스크립트 복사 > F5로 실행 ( 중지는 터미널 클릭 후 Ctrl + C 또는 상단에 빨간 박스 버튼)

 

# 1. install
# pip install pyautogui pyscreeze pillow selenium webdriver-manager opencv-python

import os
import json
import requests
import threading
import time
from selenium import webdriver
from selenium.webdriver.chrome.service import Service
from webdriver_manager.chrome import ChromeDriverManager
import pyautogui


def capture_network_calls(url, output_file, whitelist, interval=5):

    options = webdriver.ChromeOptions()
    options.set_capability('goog:loggingPrefs', {'performance': 'ALL'})

    service = Service(ChromeDriverManager().install())
    driver = webdriver.Chrome(service=service, options=options)
    driver.set_window_size(1300, 800)
    counter = 0
    timer = None

    def reset_timer():
        nonlocal timer
        if timer:
            timer.cancel()
        timer = threading.Timer(80, on_timeout)  # 80초 타이머 설정
        timer.start()

    def on_timeout():
        print("동작 않음: 2분 동안 counter가 증가하지 않았습니다.")
        try:
            # 첫 번째 이미지를 클릭
            first_image_path = "1.png"  # 첫 번째 클릭할 이미지 파일 경로
            first_button_location = pyautogui.locateOnScreen(first_image_path, confidence=0.8)
            if first_button_location:
                pyautogui.click(first_button_location)
                print(f"Clicked on the first button at {first_button_location}.")
                time.sleep(2)  # 2초 대기

                x, y = pyautogui.center(first_button_location)
                pyautogui.moveTo(x - 30, y + 30)

                time.sleep(2)  # 2초 대기


                # 두 번째 이미지를 클릭
                second_image_path = "2.png"  # 두 번째 클릭할 이미지 파일 경로
                second_button_location = pyautogui.locateOnScreen(second_image_path, confidence=0.8)
                if second_button_location:
                    pyautogui.click(second_button_location)
                    print(f"Clicked on the second button at {second_button_location}.")
                    reset_timer()  # 두 번째 이미지를 클릭한 후 타이머를 다시 초기화
                else:
                    print("Second button image not found on the screen.")
            else:
                print("First button image not found on the screen.")
        except Exception as e:
            print(f"Error during pyautogui operation: {e}")

    try:
        driver.get(url)
        network_calls = []
        reset_timer()  # 타이머 초기화

        print("Capturing network calls and downloading .ts files. Press Ctrl+C to stop...")
        while True:
            logs = driver.get_log('performance')
            for log in logs:
                log_json = json.loads(log['message'])['message']
                if log_json['method'] == 'Network.requestWillBeSent':
                    request_url = log_json['params']['request']['url']

                    if any(allowed in request_url for allowed in whitelist):
                        if request_url not in network_calls:
                            network_calls.append(request_url)

                        if request_url.endswith('.ts'):
                            counter += 1
                            reset_timer()  # counter가 증가했으므로 타이머 재설정

            with open(output_file, 'w') as f:
                json.dump(network_calls, f, indent=4)

            time.sleep(interval)

    except KeyboardInterrupt:
        print("\nStopping network capture.")
    finally:
        if timer:
            timer.cancel()  # 타이머 종료
        driver.quit()


# Example usage
url = "https://academia.spartacodingclub.kr"  # Replace with the target URL
output_file = "network_calls.json"
whitelist = [
    "https://s3.ap-northeast-2.amazonaws.com/academia.spartacodingclub.kr/media/",
]

capture_network_calls(url, output_file, whitelist)

 

 

 

이상입니다.