반응형
Notice
Recent Posts
Recent Comments
Link
일 | 월 | 화 | 수 | 목 | 금 | 토 |
---|---|---|---|---|---|---|
1 | ||||||
2 | 3 | 4 | 5 | 6 | 7 | 8 |
9 | 10 | 11 | 12 | 13 | 14 | 15 |
16 | 17 | 18 | 19 | 20 | 21 | 22 |
23 | 24 | 25 | 26 | 27 | 28 |
Tags
- Uipath 기초
- 가상환경설치
- 왕초보 파이썬 실행
- 네이버 로그인 캡챠해결
- 파이썬 가상환경 설치방법
- Element is not clickable at point
- 네이버 로그인 영수증 해결
- UiPath
- 네이버커머스API
- 날짜 정규식
- selenium
- 파이썬네이버부동산
- pywinauto 윈도우제어
- pycdas.exe
- pycdc.exe
- uipath 입문
- pywinauto
- venv 설치
- 네이버 로그인 하기
- 파이썬 네이버 로그인
- 커머스API
- pywinauto 윈도우
- 네이버매물크롤링
- 파이썬 환경설정
- 파이썬 가상환경 설치
- Python
- 네이버부동산크롤링
- Uipath 설치방법
- vscode venv 설치
- Selenium 셀렉터잡기
Archives
- Today
- Total
콘솔워크
파이썬 셀레니움 html 특정영역 드래그하여 복사하는 코드 본문
반응형
# 새 탭에서 URL로 이동
driver.get(product_url)
time.sleep(1)
wait = WebDriverWait(driver, 10)
wait.until(EC.presence_of_element_located((By.XPATH, '//h2[contains(text(), "상품 설명")]')))
# 상품 설명 영역의 시작점 찾기
start_element = WebDriverWait(driver, 10).until(
EC.presence_of_element_located((By.CSS_SELECTOR, "div.ProductExplanation"))
)
# 드래그할 영역의 끝점 찾기
end_element = WebDriverWait(driver, 10).until(
EC.presence_of_element_located((By.CSS_SELECTOR, "div.ProductExplanation__commentBody"))
)
# 시작 요소가 보이도록 스크롤
driver.execute_script(
"""
arguments[0].scrollIntoView({block: 'center', behavior: 'instant'});
""",
start_element,
)
time.sleep(1)
# JavaScript로 텍스트 선택
select_script = """
const range = document.createRange();
range.setStartBefore(arguments[0]);
range.setEndAfter(arguments[1]);
const selection = window.getSelection();
selection.removeAllRanges();
selection.addRange(range);
return true;
"""
driver.execute_script(select_script, start_element, end_element)
time.sleep(1)
# 복사 동작 수행
actions = ActionChains(driver)
actions.key_down(Keys.CONTROL).send_keys("c").key_up(Keys.CONTROL)
actions.perform()
time.sleep(0.5)
# 클립보드 내용 확인
clipboard_content = pyperclip.paste()
print("클립보드에 복사된 내용 길이:", len(clipboard_content))
반응형
'프로그래밍 > python' 카테고리의 다른 글
셀레니움 크롬 개발자 도구 시크릿모드 복사붙여넣기 안됨 (1) | 2024.06.17 |
---|---|
두 엑셀파일을 비교하여, 다른 데이터가 있는 경우 색깔로 표시해주는 파이썬 코드 (0) | 2024.05.09 |
python pyinstaller로 만든 exe 파일을 inno setup 6 버전으로 만들기(한글 설치) (0) | 2024.04.19 |
openpyxl 엑셀에 특정열이 없는 경우 오른쪽으로 하나씩 추가하는 코드 (0) | 2024.04.13 |
python 코드로 pnu(필지고유번호) 번호 만드는 방법 (0) | 2024.04.09 |