python + selenium, bs4 환경 세팅하기
·
python/python_selenium
1. python 다운로드https://www.python.org/downloads/ 2.python 을 path 에 추가하기 선택 후 install Now3. visual studio code 다운로드 (다음버튼 계속누르면 됨) Visual Studio Code - Code Editing. RedefinedVisual Studio Code is a code editor redefined and optimized for building and debugging modern web and cloud applications.  Visual Studio Code is free and available on your favorite platform - Linux, macOS, and Windows.code.vi..
selenium_quiz2
·
python/python_selenium
- 웹스크래핑을 이용하여 나만의 비서를 만들기 - 네이버에서 오늘 서울의 날씨 정보를 가져옴. 다음 뉴스 홈에서 뉴스 3건을 가져옴 (헤드라인이 현재 사라짐) it뉴스 3건을 가져옴. 해커스 어학원 홈페이지에서 오늘의 회화 지문을 가져옴. # 웹스크래핑을 이용하여 나만의 비서를 만들기 # 1. 네이버에서 오늘 서울의 날씨 정보를 가져옴. # 2. 다음 뉴스 홈에서 뉴스 3건을 가져옴 (헤드라인이 현재 사라짐) # 3. it뉴스 3건을 가져온다. # 4. 해커스 어학원 홈페이지에서 오늘의 회화 지문을 가져온다. from bs4 import BeautifulSoup import requests import random import re def create_soup(url): print("="*50) head..
selenium_quiz1
·
python/python_selenium
목적 : 네이버 부동산에서 송파 헬리오시티 검색 후 목록 추출하기 # 네이버 부동산에서 `송파 헬리오시티` 검색 후 목록 추출하기 from bs4 import BeautifulSoup import time from selenium import webdriver from selenium.webdriver.common.by import By from selenium.webdriver.common.keys import Keys browser = webdriver.Chrome() url = "" browser.get(url) time.sleep(1) # 송파 헬리오시티로 이동 후 목록이 로딩될동안 대기. items = browser.find_element(By.ID, "search_input") items.se..
Headless 크롬
·
python/python_selenium
from bs4 import BeautifulSoup import time from selenium import webdriver options = webdriver.ChromeOptions() # headless 즉, 창을 띄우지않고 랜더링을 통해 크롤링 가능 # 다만 해당의 경우, user-agent가 headless로 인식되어 몇몇 사이트에서 막을 수 있다. options.headless = True options.add_argument("window-size=1920x1080") # 아래와 같이 user-agent를 나와 같은 상태로 만들 수 있음. options.add_argument("user-agent = Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleW..
Selenium 활용2
·
python/python_selenium
import requests from bs4 import BeautifulSoup header = {'User-Agent':("Mozilla/5.0 (Windows NT 10.0; Win64; x64) " "AppleWebKit/537.36 (KHTML, like Gecko) Chrome/112.0.0.0 Safari/537.36") ,"Accept-Language":"ko-KR,ko"} # 한글 언어 웹페이지를 불러옴 url = "" res = requests.get(url, headers=header) res.raise_for_status() soup = BeautifulSoup(res.text, "lxml") # with open("movie.html", "w", encoding="utf8") as..
Selenium 활용1
·
python/python_selenium
목표 : 네이버 항공에서 제주도행 항공권 찾기 from selenium import webdriver from selenium.webdriver.common.by import By # webdriverWait을 사용하기 위한 import from selenium.webdriver.support.ui import WebDriverWait from selenium.webdriver.support import expected_conditions as EC import time def wait_until(xpath_str): # 아래값이 나올때까지 기다림 ( 다만 나오지 않는 경우 최대 3초까지 기다림. ) WebDriverWait(browser, 3).until(EC.presence_of_element_loc..
Selenium 심화
·
python/python_selenium
from selenium import webdriver from selenium.webdriver.common.by import By from selenium.webdriver.common.keys import Keys # webdriverWait을 사용하기 위한 import from selenium.webdriver.support.ui import WebDriverWait from selenium.webdriver.support import expected_conditions as EC import time browser = webdriver.Chrome() browser.get("") # 로그인 버튼을 클릭 후 이동 elem = browser.find_element(By.CLASS_NAME,"link..
Selenium 기본
·
python/python_selenium
# 직접 웹브라우저를 컨트롤하여 webscraping # 현재 버전에 맞는 chrome driver.exe파일 다운로드해야됨 from selenium import webdriver from selenium.webdriver.common.by import By from selenium.webdriver.common.keys import Keys # 현재 폴더에 있음 = ./, 적지 않아도 된다. browser = webdriver.Chrome() #"./chromedriver.exe" browser.get("") # selenium 문법이 변경되었다. # find_element_by_class_name 은 하단과 같이 명시되어야 함. # 꼭 from selenium.webdriver.common.by im..