본문 바로가기
728x90
반응형

셀레니움37

셀레니움 - 요소 가운데로 스크롤하기 element = driver.find_element_by_xpath('//*[text()="사용감 없음"]')scrollElementIntoMiddle = "var viewPortHeight = Math.max(document.documentElement.clientHeight, window.innerHeight || 0);"\ + "var elementTop = arguments[0].getBoundingClientRect().top;"\ + "window.scrollBy(0, elementTop-(viewPortHeight/2));";\driver.execute.. 2024. 5. 23.
셀레니움 - URL 연결 요청 차단 확장 도구(HTTP Request Blocker) https://chromewebstore.google.com/detail/http-request-blocker/eckpjmeijpoipmldfbckahppeonkoeko?hl=en-US HTTP Request BlockerThis extension blocks HTTP Request based on configurable URL patterns.chromewebstore.google.com   출처 : https://stackoverflow.com/questions/27863094/how-to-block-a-url-in-chromes-developer-tools-network-monitor How to block a URL in Chrome's developer tools network monitorI .. 2024. 4. 26.
셀레니움 - 새 탭 열기 & 새 창 열기 driver.switch_to.new_window('tab') driver.switch_to.new_window('window') 2023. 10. 5.
셀레니움 - 특정 태그 범위 표시하기 driver.execute_script("arguments[0].style.border='2px solid red';", elem) # 태그 범위 표시 2023. 7. 29.
셀레니움 - 아직 안올라온 크롬드라이브 최신 버전 설치하기 https://googlechromelabs.github.io/chrome-for-testing/ Chrome for Testing availability This page lists the latest available cross-platform Chrome for Testing versions and assets per Chrome release channel. Consult our JSON API endpoints if you’re looking to build automated scripts based on Chrome for Testing release data. Last updated @ 20 googlechromelabs.github.io 2023. 7. 28.
셀레니움 - html 서식도 포함해서 텍스트 복사하기(klembord) example.py import time import klembord from selenium import webdriver from selenium.webdriver.chrome.options import Options from selenium.webdriver.common.keys import Keys from selenium.webdriver.common.action_chains import ActionChains options = Options() options.add_argument("--headless") options.add_argument("--disable-gpu") options.add_argument("--no-sandbox") options.add_argument("--disable.. 2023. 7. 23.
셀레니움 - 크롬 다운그레이드 만약 크롬드라이브가 현재 컴퓨터에 설치된 최신 버전(chrome://version에서 확인 가능)을 지원하지 않는 경우 기존 크롬을 삭제해서 낮은 버전으로 설치하는 다운그레이드가 필요함 크롬 버전별 다운로드 모음 사이트(uptodown) https://google-chrome.en.uptodown.com/windows/versions Older versions of Google Chrome (Windows) | Uptodown exe 115.0.5790.99 Jul 19, 2023 exe 114.0.5735.199 Jun 28, 2023 zip 114.0.5735.134 Jun 16, 2023 zip 114.0.5735.106 Jun 7, 2023 exe 113.0.5672.127 May 29, 2023.. 2023. 7. 22.
셀레니움 - xpath 자바스크립트로 클릭하기 (javascript error: $x is not defined) 방법 1. marketplace_button = WebDriverWait(driver, 20).until(EC.element_to_be_clickable((By.XPATH, '//span[contains(text(), "Marketplace")]'))) marketplace_button.click() 방법 2. marketplace_button = WebDriverWait(driver, 20).until(EC.element_to_be_clickable((By.XPATH, '//span[contains(text(), "Marketplace")]'))) driver.execute_script("arguments[0].click();", marketplace_button) 출처: https://stackove.. 2023. 6. 11.
셀레니움 - xpath, 텍스트가 포함된 요소 선택(contains text) 원하는 문자열인 요소 찾기 ex) 요소의 내용이 foo인 것을 찾기 //myparent/mychild[text() = 'foo'] 원하는 문자열이 포함한(contains) 요소 찾기 ex) ABC라는 내용을 포함한 있는 요소 찾기 //*[contains(text(),'ABC')] 파이썬 사용 예시 driver.find_element_by_xpath('//span[contains(text(),"ABC")]') 자바스크립트(브라우저 개발자 도구) 사용 예시 $x("//*[contains(text(),'12:00')]") 그 문자인 것을 찾기 $x('//*[text()="네이버로 이용하기"]') 속성(class나 id) 값이 특정 문자로 시작하는 요소 찾기 $x("//div[starts-with(@class,.. 2023. 5. 7.
셀레니움 - 크롬드라이브 자동 설치 모듈 설치 pip install webdriver_manager from webdriver_manager.chrome import ChromeDriverManager def exec_chrom(): driver = webdriver.Chrome(service=Service(ChromeDriverManager().install())) return driver 2023. 3. 8.
셀레니움 - 이미지(img) 다운로드 (No urllib.urlretrieve) URL 요청 방식인 urllib.urlretrieve은 src 주소로 요청을 하는 방식이기 때문에 캡챠(자동등록방지 문자)처럼 매번 요청할 때마다 이미지가 바뀌는 경우가 있어 무용지물이 된다. 그러므로 이미 브라우저에 로드가 된 이미지를 가져오는 방법을 사용해야 한다. 방법 1. screenshot_as_png 사용 (추천) from selenium import webdriver driver = webdriver.Firefox() driver.get('https://www.webpagetest.org/') with open('filename.png', 'wb') as file: file.write(driver.find_element_by_xpath('/html/body/div[1]/div[5]/div[2.. 2023. 2. 28.
셀레니움 - 파이썬 봇 감지 우회 라이브러리(undetected-chromdriver) pypi https://pypi.org/project/undetected-chromedriver/ undetected-chromedriver ('Selenium.webdriver.Chrome replacement with compatiblity for Brave, and other Chromium based browsers.', 'Not triggered by CloudFlare/Imperva/hCaptcha and such.', 'NOTE: results may vary due to many factors. No guarantees are given, except for ongoing eff pypi.org 설치 pip install undetected-chromedriver 사용 예시 import u.. 2023. 1. 29.
728x90
반응형