3가지 옵션이 있음


1. 여따 댓글에 github username 달기, private repo에 collaborator로 추가해 놓겠음

2. https://gall.dcinside.com/mgallery/board/view/?id=thesingularity&no=375238 이거 답해주기

3. 아래는 AI완장 소스코드(파이썬) 중 일부임, 로컬로 돌려서 (기왕이면 headless 없이) 뭐가 문제인지 테스트 해주면 됨


def setup_driver():

    chrome_options = Options()

    chrome_options.add_argument("--headless")

    chrome_options.add_argument("--disable-gpu")

    chrome_options.add_argument("--no-sandbox")

    chrome_options.add_argument("--disable-dev-shm-usage")

    chrome_options.add_argument('--ignore-certificate-errors')

    chrome_options.add_argument("--disable-blink-features=AutomationControlled") # 이하 selenium 감지 우회를 위한 눈물의 똥꼬쇼

    chrome_options.add_experimental_option("excludeSwitches", ["enable-automation"])

    chrome_options.add_experimental_option('useAutomationExtension', False)


    user_agent = "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/58.0.3029.110 Safari/537.3"

    chrome_options.add_argument(f"user-agent={user_agent}")

    

    chrome_options.add_argument("--window-size=1920,1080")


    driver = webdriver.Chrome(options=chrome_options)


    driver.execute_cdp_cmd('Page.addScriptToEvaluateOnNewDocument', {

        'source': """

            Object.defineProperty(navigator, 'webdriver', {

                get: () => undefined

            })

        """

    })


    driver.execute_script("""

  const getParameter = WebGLRenderingContext.getParameter;

  WebGLRenderingContext.prototype.getParameter = function(parameter) {

    if (parameter === 37445) {

      return 'NVIDIA Corporation';

    }

    if (parameter === 37446) {

      return 'NVIDIA GeForce GTX 660 Ti OpenGL Engine';

    }

    return getParameter(parameter);

  };

  

  Object.defineProperty(navigator, 'plugins', {

    get: () => [1, 2, 3, 4],

  });

  Object.defineProperty(navigator, 'languages', {

    get: () => ['en-US', 'en'],

  });

  

  Intl.DateTimeFormat = class extends Intl.DateTimeFormat {

    constructor() {

      super();

      return new Proxy(super(), {

        get(target, prop, receiver) {

          if (prop === 'resolvedOptions') {

            return () => {

              return Object.assign({}, super.resolvedOptions(), {

                timeZone: 'Asia/Singapore'

              });

            };

          }

          return Reflect.get(target, prop, receiver);

        },

      });

    }

  };

""")


    driver.get("https://www.dcinside.com/' target="_blank">https://www.dcinside.com/")


    cookie = load_encrypted_cookie(encryption_key)

    if cookie:

        driver.get("https://www.dcinside.com/' target="_blank">https://www.dcinside.com/")

        driver.delete_all_cookies()  # Clear any existing cookies

        for c in cookie:

            if 'expiry' in c:

                c['expiry'] = int(c['expiry'])

            driver.add_cookie(c

        driver.refresh()

    else:

        perform_login(driver, username, password)


    return driver



@app.route('/upload_post', methods=['POST'])

def upload_post_endpoint():

    

    content_type = request.headers.get('Content-Type')

    if content_type != 'application/json':

        return jsonify({"error": "Incorrect Content-Type. Expected application/json"}), 400


    raw_data = request.data

    app.logger.debug('Raw data: %s', raw_data)


    try:

        json_data = request.get_json()

        if json_data is None:

            raise ValueError("No JSON data found")


    except ValueError as e:

        app.logger.error('No JSON data found: %s', e)

        return jsonify({"error": "No JSON data found"}), 400


    except Exception as e:

        app.logger.error('Error parsing JSON: %s', e)

        return jsonify({"error": "JSON parsing failed"}), 400


    if not json_data:

        return jsonify({"error": "No JSON data received"}), 400

    

    app.logger.debug('JSON data: %s', json_data)

        

    gallery_id = json_data.get('gallery_id')

    flair_text = json_data.get('flair_text')

    title_text = json_data.get('title_text')

    content_html = json_data.get('content_html')

    

    start_chrome_debug_mode()

    driver = setup_driver()

    try:

        driver.get(f"https://gall.dcinside.com/mgallery/board/write/?id={gallery_id}")

        time.sleep(10)


        WebDriverWait(driver, 2).until(

            EC.element_to_be_clickable((By.XPATH, f"//li[contains(.,'{flair_text}')]"))

        ).click()


        subject_field = WebDriverWait(driver, 1).until(

            EC.element_to_be_clickable((By.ID, "subject"))

        )

        subject_field.click()

        subject_field.send_keys(title_text)


        driver.find_element(By.ID, "chk_html").click()


        html_content_area = WebDriverWait(driver, 1).until(

            EC.presence_of_element_located((By.ID, "tx_canvas_source"))

        )

        html_content_area.click()

        html_content_area.send_keys(content_html)


        driver.find_element(By.ID, "chk_html").click()


        submit_button = WebDriverWait(driver, 1).until(

            EC.element_to_be_clickable((By.CSS_SELECTOR, ".btn_svc"))

        )

        submit_button.click()


        time.sleep(1)


        try:

            WebDriverWait(driver, 5).until(EC.alert_is_present())

            alert = driver.switch_to.alert

            alert_text = alert.text

            alert.accept()

            return jsonify({"error": alert_text}), 500

        except TimeoutException:

            pass


        return jsonify({"success": "Post uploaded successfully"}), 200

    except Exception as e:

        error_message = f"An error occurred: {e.__class__.__name__}, Message: {e}"

        app.logger.error(error_message)

        traceback.print_exc()

        return jsonify({"error": error_message}), 500

    finally:

        driver.quit()


로그인 쿠키는 PHPSESSID임

본인 계정 쿠키값 가져와서 넣기만 하면 작동할? 듯