반응형 DEVEL/PYTHON8 Python Playwright를 이용한 스크래핑 Python에서 Playwright를 사용하여 웹 스크래핑을 수행하는 방법을 단계별로 설명하겠습니다. Playwright는 강력한 웹 자동화 도구로, 다양한 브라우저를 지원하며 빠르고 안정적인 스크래핑을 할 수 있게 해줍니다.1. Playwright 설치먼저 Playwright를 설치해야 합니다. Python 환경에서 아래 명령어를 실행하세요:pip install playwright설치 후 브라우저 이진 파일을 다운로드해야 합니다.playwright install2. Playwright 기본 사용법Playwright를 사용하여 웹 페이지를 열고 데이터를 스크래핑하는 기본 예제를 보여드리겠습니다.from playwright.sync_api import sync_playwright# Playwright 실행.. 2024. 8. 31. PYTHON 두장의 이미지 합성하기 필요한 패키지를 설치해야 합니다. 다음 명령을 사용하여 OpenCV를 설치할 수 있습니다. pip install opencv-python 그런 다음, 다음의 코드를 사용하여 이미지를 합성할 수 있습니다. import cv2 import numpy as np # 이미지 파일 경로 image1_path = "image1.jpg" image2_path = "image2.jpg" # 이미지 불러오기 image1 = cv2.imread(image1_path) image2 = cv2.imread(image2_path) # 이미지 크기 조정 (합성하기 전에 두 이미지가 동일한 크기여야 함) image1 = cv2.resize(image1, (image2.shape[1], image2.shape[0])) # 이미지 합.. 2024. 4. 9. PYTHON ChatGPT API 예제 Python에서는 OpenAI의 공식적으로 지원하는 openai 라이브러리를 사용해서 ChatGPT API를 사용할 수 있다. pip install openai import openai openai.api_key = 'your-api-key' response = openai.Completion.create( engine="text-davinci-002", prompt="Translate the following English text to French: '{text}'", # {text} 부분을 원하는 텍스트로 바꾸세요 max_tokens=60 ) print(response.choices[0].text.strip()) openai 라이브러리는 기본적으로 python 객체를 반환하므로 별도로 JSON을 파.. 2023. 7. 25. PYTHON 내 주소에 이더리움 거래 조회 from web3 import Web3 # web3 인스턴스 초기화 w3 = Web3(Web3.HTTPProvider('https://mainnet.infura.io/v3/YOUR-INFURA-PROJECT-ID')) # 확인하려는 주소 my_address = '0xYourEthereumAddressHere' # 최신 블록 번호 얻기 latest_block = w3.eth.block_number # 최신 블록부터 특정 블록까지 거래 확인 for i in range(latest_block - 10**5, latest_block): block = w3.eth.get_block(i, full_transactions=True) for tx in block.transactions: if tx['to'] == my.. 2023. 7. 18. [PYTHON] requests 구글 검색 import requests from bs4 import BeautifulSoup # 검색할 키워드 keyword = '파이썬' # 검색 결과 페이지 URL url = f'https://www.google.com/search?q={keyword}' # HTTP GET 요청 보내기 response = requests.get(url) # 응답 코드가 200인 경우에만 처리 if response.status_code == 200: # HTML 파싱 soup = BeautifulSoup(response.text, 'html.parser') # 검색 결과 출력 search_results = soup.select('.g') for result in search_results: print(result.text) el.. 2023. 4. 3. [PYTHON] selenium 구글 검색 셀레니움, 크롬 드라이버 설치 !pip install selenium !apt-get update # apt 패키지 리스트 업데이트 !apt install chromium-chromedriver 예제코드 from selenium import webdriver from selenium.webdriver.common.keys import Keys import time # 크롬 드라이버 경로 설정 driver_path = '/usr/lib/chromium-browser/chromedriver' # 웹드라이버 옵션 설정 options = webdriver.ChromeOptions() options.add_argument('--headless') # 화면에 브라우저를 띄우지 않음 # 웹드라이버 객체 생성 driv.. 2023. 4. 3. Python 유튜브 채널 구독하기 Google API Python 라이브러리 pip install --upgrade google-api-python-client 유튜브 데이터 API 예제 코드 # -*- coding: utf-8 -*- # Sample Python code for youtube.subscriptions.insert # See instructions for running these code samples locally: # https://developers.google.com/explorer-help/guides/code_samples#python import os import google_auth_oauthlib.flow import googleapiclient.discovery import googleapiclient... 2023. 3. 16. Python 셀레니움으로 네이버 로그인하기 selenium 패키지 설치 pip install selenium 구글 검색 from selenium import webdriver from selenium.webdriver.common.keys import Keys driver = webdriver.Chrome() driver.get("https://www.google.com") search_box = driver.find_element_by_name("q") search_box.send_keys("python selenium example") search_box.send_keys(Keys.RETURN) results = driver.find_elements_by_class_name("g") for result in results: print(resu.. 2023. 3. 16. 이전 1 다음 반응형