from utils import log import time from database import is_product_processed, mark_product_processed def modify_products(driver): # 총 상품 수 확인 total_products_text = driver.find_element_by_xpath("//span[contains(.,'총')]").text total_products = int(''.join(filter(str.isdigit, total_products_text))) total_pages = (total_products + 19) // 20 current_page = 1 completed_products = 0 while current_page <= total_pages: # 현재 페이지의 상품 수 계산 products_on_page = min(20, total_products - completed_products) for i in range(1, products_on_page + 1): try: product_title_element = driver.find_element_by_xpath(f"//div[{i}]/li/div/div/div[2]/div/div/div/div") product_title_element.click() # 상품 수정 페이지 열기 time.sleep(2) product_id_element = driver.find_element_by_xpath("//div[3]/div/div[3]/div/div[3]/div/div/div") product_id = product_id_element.text if is_product_processed(product_id): log(f"상품 {product_id}는 이미 처리됨.") close_button = driver.find_element_by_css_selector(".anticon-close path") close_button.click() continue # 상품 수정 작업 수행 # 여기에 상품 수정 관련 코드 추가 mark_product_processed(product_id) log(f"상품 {product_id} 처리 완료.") completed_products += 1 log(f"진행 상황: {completed_products}/{total_products} ({(completed_products/total_products)*100:.2f}%)") except Exception as e: log(f"상품 {i} 확인 중 오류 발생: {e}", exc_info=True) # 다음 페이지로 이동 if current_page < total_pages: try: next_page_button = driver.find_element_by_css_selector(".ant-pagination-next > .ant-pagination-item-link") next_page_button.click() time.sleep(5) current_page += 1 except Exception as e: log(f"다음 페이지로 이동하는 중 오류 발생: {e}", exc_info=True) break else: log("모든 페이지 처리 완료. 작업 종료.") break log("상품 수정 작업이 완료되었습니다.") def navigate_to_new_product_registration(driver): """신규 상품 등록 페이지로 이동합니다.""" log("신규상품등록 버튼 클릭...") new_product_button = driver.find_element_by_xpath("//span[contains(.,'신규 상품 등록')]") new_product_button.click() time.sleep(1) # 각 페이지의 상품들을 순회하며 "수정작업" 수행 while True: for i in range(1, 21): # 각 페이지에 최대 20개의 상품 try: product_title_element = driver.find_element_by_xpath(f"//div[{i}]/li/div/div/div[2]/div/div/div/div") product_id = product_title_element.text log(f"상품 {product_id} 확인 중...") if is_product_processed(product_id): log(f"상품 {product_id}는 이미 처리됨.") continue # 여기에 "수정작업" 로직 추가 # 예: product_title_element.click() time.sleep(2) #python Copy code # 여기에 "수정작업" 세부 과정을 추가하세요. 예를 들어, 상품명 변경, 키워드 추가 등 # 상품 처리 완료 후, SQLite DB에 상품 ID 저장 mark_product_processed(product_id) log(f"상품 {product_id} 처리 완료.") except Exception as e: log(f"상품 {i} 확인 중 오류 발생: {e}", exc_info=True) continue # 다음 페이지로 이동 try: next_page_button = driver.find_element_by_css_selector(".ant-pagination-next > .ant-pagination-item-link") if not next_page_button.is_enabled(): log("더 이상 페이지가 없음. 작업 종료.") break next_page_button.click() time.sleep(5) except Exception as e: log(f"다음 페이지로 이동하는 중 오류 발생: {e}", exc_info=True) break