본문 바로가기
728x90
반응형

파이썬80

셀레니움 - 특정 태그 범위 표시하기 driver.execute_script("arguments[0].style.border='2px solid red';", elem) # 태그 범위 표시 2023. 7. 29.
셀레니움 - 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.
파이썬 - 로딩바(Progress Bar) 구현 모듈(tqdm) 모듈 설치 pip install tqdm 사용 예시 from time import sleep from tqdm import tqdm for i in tqdm(range(10)): sleep(1) 출처: https://stackoverflow.com/questions/3160699/python-progress-bar Python Progress Bar How do I use a progress bar when my script is doing some task that is likely to take time? For example, a function which takes some time to complete and returns True when done. How can I display a stac.. 2023. 7. 17.
파이썬 - PyAutoGUI가 안될 경우 대체 가능한 라이브러리(PyDirectInput) 기본 PyAutoGUI는 가상 키(VK)와 mouse_event() 및 keybd_event() win32 함수를 사용하고 있는데 이는 일부 응용 프로그램들, 비디오 게임이나 DirectX에 지원하지 않아 제대로 작동하지 않을 수 있다. 그래서 PyDirectInput 라이브러리는 DirectInput 스캔 코드와 SendInput() win32 같은 최신 방식을 사용해 이 문제를 해결할 수 있다. PyPi - PyDirectInput https://pypi.org/project/PyDirectInput/ PyDirectInput Python mouse and keyboard input automation for Windows using Direct Input. pypi.org 코드 예제 >>> impo.. 2023. 7. 15.
셀레니움 - 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.
파이썬 - 리눅스에서 GPT 명령어 사용하기 모듈 설치 pip install openai ~/dev/gpt.py import openai import sys openai.api_key = "자신의 API 토큰을 여기에 입력" messages = [ {"role": "system", "content": "You are a helpful assistant."}, ] def request(text:str): global messages if len(messages) >= 30: messages = messages[-10:] query = text messages.append({"role": "user", "content": query}) response = openai.ChatCompletion.create( model="gpt-3.5-turbo", m.. 2023. 5. 22.
셀레니움 - 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.
파이썬 - 레지스트리 조작(winreg) import winreg # 레지스트리 키 생성 key_path = r"Software\MyExampleKey" try: key = winreg.CreateKey(winreg.HKEY_CURRENT_USER, key_path) print("키 생성 성공") except: print("키 생성 실패") # 레지스트리 키에 값 설정 value_name = "ExampleValue" value_data = "Hello, Registry!" try: winreg.SetValueEx(key, value_name, 0, winreg.REG_SZ, value_data) winreg.CloseKey(key) print("값 설정 성공") except: print("값 설정 실패") # 레지스트리 키에서 값 읽기 try.. 2023. 5. 5.
파이썬 - pyinstaller 관리자 권한으로 실행 하기 --uac-admin 옵션을 추가하고 빌드를 하면 관리자 권한으로 실행이 가능하다. 예시 pyinstaller -w --uac-admin test.py 출처: https://dev-dream.tistory.com/4 pyinstaller 로 exe 만들 때 관리자 권한으로 실행하기 python 으로 프로그램을 만들면 exe (실행파일) 형태로 배포할 경우가 있다. py2exe 를 주로 썼는데 setup 파일 만드는게 불편했는데 pyinstaller 를 활용하면 쉽게 만들 수 있다. pip3 install pyinstaller 로 pyins dev-dream.tistory.com 2023. 5. 5.
파이썬 - 맥 주소 변경(changeMAC) changeMAC.py (관리자 권한 필요) from winreg import * import os, time def run(adapterName, adapterType="Wi-Fi"): aReg = ConnectRegistry(None, HKEY_LOCAL_MACHINE) aKey = OpenKey(aReg, r"SYSTEM\CurrentControlSet\Control\Class\{4d36e972-e325-11ce-bfc1-08002be10318}") oKey = None sValue = None for i in range(255): try: aValue_name = EnumKey(aKey, i) oKey = OpenKey(aKey, aValue_name) sValue = QueryValueEx(oK.. 2023. 5. 2.
아파치 - 파이썬 패키지 pip로 설치 sudo mkdir /var/www/.local sudo mkdir /var/www/.cache sudo chown www-data.www-data /var/www/.local sudo chown www-data.www-data /var/www/.cache sudo -H -u www-data pip install CoolProp www-data로 /bin/sh 연결 sudo su www-data -s /bin/sh 출처: https://stackoverflow.com/questions/39471295/how-to-install-python-package-for-global-use-by-all-users-incl-www-data How to install Python Package for global us.. 2023. 3. 29.
시스템 보안 - pwntools pwntools는 리눅스 환경에서 실행 프로그램의 익스플로잇을 작성하도록 도움을 주는 파이썬 라이브러리이다. CTF에서도 유용하게 사용될 수 있다. pip 설치 명령어 python3 -m pip install --upgrade pwntools 사용 예제 >>> conn = remote('ftp.ubuntu.com',21) >>> conn.recvline() # doctest: +ELLIPSIS b'220 ...' >>> conn.send(b'USER anonymous\r\n') >>> conn.recvuntil(b' ', drop=True) b'331' >>> conn.recvline() b'Please specify the password.\r\n' >>> conn.close() nc(NetCat), .. 2023. 3. 25.
728x90
반응형