[Python] How to upload photos to tinyMCE via Selenium?

Discussão em 'Python' iniciado por Stack, Fevereiro 19, 2025.

  1. Stack

    Stack Membro Participativo

    I need to post pictures of my computer on a TinyMCE-based bulletin board, but I don't see any file-related items like input[type=file] in the DOM there. All I see is a button to pop up the File Explorer window.


    from selenium import webdriver
    from selenium.webdriver.common.by import By
    from selenium.webdriver.chrome.service import Service
    from webdriver_manager.chrome import ChromeDriverManager
    import time
    import pyautogui # pyautogui 임포트
    import pandas as pd

    # 데이터 로드
    dts = pd.read_csv("set.csv", encoding="CP949")
    dts = dts.transpose()

    base_folder = r"C:\Users\todgu\Documents\Code\Python\#BP\10manwon\imgs\set" # 변경해야 함
    new_folder_name = "imges"

    url = "https://cafe.daum.net/paradise14/VthA"
    options = webdriver.ChromeOptions()
    options.add_argument(r'user-data-dir=C:\User Data')

    service = Service(ChromeDriverManager().install())
    driver = webdriver.Chrome(service=service, options=options)
    driver.get(url)
    time.sleep(1)

    # 첫 번째 iframe으로 이동
    iframe = driver.find_element(By.XPATH, '//*[@id="down"]')
    driver.switch_to.frame(iframe)

    # 글쓰기 버튼 클릭
    Button = driver.find_element(By.XPATH, '//*[@id="article-write-btn"]')
    driver.execute_script("arguments[0].scrollIntoView();", Button)
    Button.click()
    time.sleep(1.5)

    # 제목 입력
    driver.find_element(By.XPATH, '//*[@id="article-title"]/input').click()
    driver.find_element(By.XPATH, '//*[@id="article-title"]/input').send_keys(dts.iloc[0, 0])

    # 두 번째 iframe으로 이동
    iframe = driver.find_element(By.XPATH, '//*[@id="keditorContainer_ifr"]')
    driver.switch_to.frame(iframe)

    # 본문 입력
    driver.find_element(By.XPATH, '//*[@id="tinymce"]').click()
    driver.find_element(By.XPATH, '//*[@id="tinymce"]').send_keys(dts.iloc[1, 0])

    Continue reading...

Compartilhe esta Página