옵션페이지 수정 중

This commit is contained in:
R5600U_PC 2024-06-18 16:17:02 +09:00
parent 429d815dd1
commit d36d7850d9
1 changed files with 43 additions and 19 deletions

View File

@ -19,6 +19,37 @@ from img_trans.image_trans import image_trans
# 로거 인스턴스 가져오기
logger = logging.getLogger('default_logger')
def modify_option_page2(driver, product_info, translator, login_info):
# 1. 현재 옵션에 대한 정보 수집
options_info = collect_option_data(driver)
# 2. 옵션타입이 단일옵션상품이 아닌지 체크
if not is_single_option_product(driver):
# 3. 각 옵션타입별로 낮은가격순으로 정렬
sort_options_by_price(driver, options_info)
# 4. 미끼상품 체크 및 제외
options_info = filter_out_bait_items(options_info)
# 5. 각 옵션타입별로 옵션아이템 가격에 따라 상품 선택
select_valid_options(driver, options_info, login_info['whether_simpleMode'])
# 6. 선택된 옵션들의 원본 옵션명과 옵션이미지 수집
option_names, option_images = collect_option_names_and_images(driver, options_info)
# 7. 수집된 원본 옵션명은 AI 처리 메서드를 통해 번역 및 편집 후 입력
update_option_names(driver, option_names, translator)
# 8. 수집된 옵션 이미지 URL은 이미지 번역 및 업로드 과정 수행
update_option_images(driver, option_images, translator)
# 기타 작업이 필요한 경우 추가
finalize_modifications(driver, options_info)
# 저장 작업 등
save_changes(driver)
def modify_option_page(driver, product_info, translator, login_info):
simpleMode = login_info['whether_simpleMode']
@ -162,7 +193,8 @@ def modify_option_page(driver, product_info, translator, login_info):
logger.debug(f"옵션타입 {option_idx}에 대한 처리 시작")
logger.debug("가격 낮은 순으로 정렬")
# low_price_order_xpath = f"//div[{option_idx}]/div/div/div[2]/div/div/div[4]/div[2]/div[2]/div/div[4]/button"
low_price_order_css = "div#productMainContentContainerId div:nth-child(2) > div > button[type=\"button\"]:nth-child(3)"
# low_price_order_css = f"div#productMainContentContainerId div:nth-child(2) > div > button[type=\"button\"]:nth-child(3)"
low_price_order_css = f"div#productMainContentContainerId div:nth-child({option_idx}) > div > div > div.ant-collapse-content.ant-collapse-content-active > div > div > div.sc-cAkrUM.flTgaK > div.ant-row.ant-row-space-between.ant-row-middle.css-1li46mu > div:nth-child(2) > div > button[type=\"button\"]:nth-child(3)"
# click_element(driver, 'XPATH', low_price_order_xpath, 10, 'js')
click_element(driver, 'CSS_SELECTOR', low_price_order_css, 10, 'js')
if not simpleMode: # 심플모드일 경우 옵션 편집하지 않음. 옵션 번역만.
@ -525,28 +557,20 @@ def collect_option_data(driver):
logger.debug("단일 상품이므로 옵션 정보 수집을 생략합니다.")
return options_info # 단일 상품일 경우 빈 딕셔너리를 반환
# 옵션 타입들의 부모 컨테이너 CSS
option_types_container_css = "div#productMainContentContainerId div.sc-bCrHVQ.fRmCVg > div:nth-child(2) > div > div > div:nth-child(2) > div > div"
# option_types_container_css = "div#productMainContentContainerId > div > div:nth-child(2) > div > div > div:nth-child(2)"
# 옵션 타입 컨테이너의 CSS 선택자
option_types_container_css = "div#productMainContentContainerId div.sc-bCrHVQ.fRmCVg > div:nth-child(2) > div > div > div:nth-child(2)"
# 옵션 타입 컨테이너 요소를 찾습니다.
option_types_container = WebDriverWait(driver, 10).until(
EC.presence_of_element_located((By.CSS_SELECTOR, option_types_container_css))
)
# 옵션 타입 요소들을 찾기 위한 CSS
option_type_css = "div.ant-row.css-1li46mu > div > div"
# 옵션 타입 갯수 수집
# 옵션 타입 갯수를 추출하기 위한 CSS 선택자
option_type_css = "div.ant-col.css-1li46mu > div.sc-stxIr.eeUZbv"
option_type_elements = option_types_container.find_elements(By.CSS_SELECTOR, option_type_css)
option_type_count = len(option_type_elements)
logger.debug(f"옵션 타입의 총 갯수 기존 : {option_type_count}")
# 옵션 타입 컨테이너의 CSS 선택자
option_type_css = "div#productMainContentContainerId div.sc-bCrHVQ.fRmCVg > div:nth-child(2) > div > div > div:nth-child(2) > div"
# 각 옵션 타입별로 `div.sc-stxIr.eeUZbv` 요소의 갯수를 확인
option_type_elements_by_css = driver.find_elements(By.CSS_SELECTOR, option_type_css)
option_type_count_by_css = len(option_type_elements_by_css)
logger.debug(f"옵션 타입의 총 갯수: {option_type_count_by_css}")
logger.debug(f"옵션 타입의 총 갯수: {option_type_count}")
for idx in range(1, option_type_count + 1):
# 옵션 타입 이름 추출
@ -623,7 +647,7 @@ def collect_option_names_and_images_and_price(driver, option_type_number, option
option_image_element = driver.find_element(By.CSS_SELECTOR, option_image_xpath)
option_image_url = option_image_element.get_attribute('src')
except Exception:
logger.debug(f"{i}번째 옵션에 이미지 없음")
logger.debug(f"{option_type_number}번 옵션타입의 {i}번째 옵션에 이미지 없음")
# 옵션 가격 수집
option_price_xpath = f"div#productMainContentContainerId li:nth-child({i}) > div > div:nth-child(1) > div > div:nth-child(3) > div:nth-child(1) > div:nth-child(2) > span > sup"
@ -634,7 +658,7 @@ def collect_option_names_and_images_and_price(driver, option_type_number, option
price_range = re.findall(r'\d+', option_price_text.replace(',', ''))
low_price, high_price = map(int, price_range) if len(price_range) == 2 else (int(price_range[0]), int(price_range[0]))
except Exception:
logger.debug(f"{i}번째 옵션에 가격 없음")
logger.debug(f"{option_type_number}번 옵션타입의 {i}번째 옵션에 가격 없음")
low_price = high_price = None
option_data.append({
@ -643,7 +667,7 @@ def collect_option_names_and_images_and_price(driver, option_type_number, option
'low_price': low_price,
'high_price': high_price
})
logger.debug(f"옵션 {i}: 이름={option_name}, 이미지 URL={option_image_url}, 가격={low_price} - {high_price}")
logger.debug(f"{option_type_number}번 옵션타입의 옵션 {i}: 이름={option_name}, 이미지 URL={option_image_url}, 가격={low_price} - {high_price}")
except Exception as e:
logger.error(f"옵션명, 이미지 및 가격 수집 중 오류 발생: {e}", exc_info=True)