본문 바로가기
반응형

Python111

[FastAPI] 비밀번호 암호화, JWT 사용하기 비밀번호 암호화 라이브러리 설치 pip install "passlib[bcrypt]" 우선 비밀번호 hash / verify 하는 예제 코드 입니다. from passlib.context import CryptContext pwd_context = CryptContext(schemes=["bcrypt"], deprecated="auto") def get_password_hash(password): return pwd_context.hash(password) def verify_password(plain_password, hashed_password): return pwd_context.verify(plain_password, hashed_password) print(get_password_hash('he.. 2023. 8. 15.
Python 실행 파일의 경로를 환경 변수에 추가하기 import sys from pathlib import Path sys.path.insert(0, Path(__file__).parent) 2023. 8. 13.
[Selenium] Scroll to Element # element 를 찾음 element = driver.find_element(By.ID, 'hello-bryan') # javascript를 실행해서 element 로 이동 driver.execute_script("arguments[0].scrollIntoView();", element) 2023. 8. 12.
[selenium] 선택된 노드의 바로 아래 자식 노드만 가져오기 아래와 같이 id="search_area" 의 바로 아래 있는 div 는 두개 입니다. 저 두개의 div 만 가져오고 싶을 때 driver.find_elements_by_css_selector('#search_area div') 이렇게 한다면 ... 안에 있는 수많은 div 들도 같이 가져오게 됩니다. 그럴 땐 아래와 같이 area = driver.find_element_by_id('search_area') div_list = area.find_elements_by_xpath('./child::div') # div_list 는 두개의 div 만 포함합니다. 2023. 8. 6.
[selenium] 부모 노드 중 검색 예) some_element 의 상위 태그 중 a 태그를 찾음 some_element.find_element_by_xpath('ancestor::a') 일단 여기까지, 나중에 정리.. 2023. 8. 6.
[selenium] element click intercepted exception in python 전 방법1로 해결 방법1 element.click() 에서 오류가 발생하면 아래와 같이 변경 from selenium.webdriver.common.keys import Keys element.send_keys(Keys.ENTER) 방법2 element 를 두번째 파라메터로 넘김 driver.execute_script("arguments[0].click();", element) 2023. 8. 4.
[selenium] move to bottom (scroll down) html = driver.find_element(By.TAG_NAME, 'html') html.send_keys(Keys.END) 이렇게 하면 한번에 끝까지 내려감. 스크롤 한번씩 내리려면 아래와 같이 SCROLL_PAUSE_TIME = 0.5 # Get scroll height last_height = driver.execute_script("return document.body.scrollHeight") while True: # Scroll down to bottom driver.execute_script("window.scrollTo(0, document.body.scrollHeight);") # Wait to load page time.sleep(SCROLL_PAUSE_TIME) # Calcula.. 2023. 8. 3.
Mac 에서 다운받은 ChromeDriver 를 권한 문제로 실행할 수 없을 때 Terminal(터미널)을 실행한 다음 다운받은 chromedriver 위치까지 이동해서 아래 명령어를 날리면 사용가능. xattr -d com.apple.quarantine chromedriver 2023. 8. 3.
[Python] 이미지 위에 투명도가 있는 PNG 이미지 합치기 PIL 사용 from PIL import Image # 배경 이미지 열기 background = Image.open('background.png') # 상단에 합칠 이미지 열기 overlay = Image.open('overlay.png') # 이미지 크기 조정 overlay = overlay.resize(background.size) # 이미지 합치기 combined = Image.alpha_composite(background.convert('RGBA'), overlay.convert('RGBA')) # 결과 이미지 저장 combined.save('combined.png') Numpy 사용 import cv2 import numpy as np # 배경 이미지 로드 background = cv2.imr.. 2023. 6. 14.
streamlit pycharm 에서 debug 사용하기 (conda) 로컬 개발환경 설정 (PyCharm) 현재 Python Interpreter 의 위치 확인 PyCharm Setting → Project Python Interpreter /opt/homebrew/anaconda3/envs/LambdaFunction/bin/python 에서 python 제외한 앞부분 /opt/homebrew/anaconda3/envs/LambdaFunction/bin 을 복사 Edit Configuration 에서 Script path 에 위에서 복사한 경로 + /streamlit 입력 Parameters 에 run main.py 입력 (실행하려는 python file name) 소스에 break point 를 찍고 디버그 실행 2023. 5. 23.
728x90
반응형