커뮤니티
포인트
쿠폰
내 강의실
국비 신청 내역
증명서
계정
로그아웃
학습 질문
개발 일지
나의 활동
답변 완료
주식 크롤링 자동화 2-7
업무자동화 종합반 v0
2주차
북마크
H
댓글
2
추천
0
조회수
11
조회수
11
답변 완료

* 겪고 있는 문제 상황을 최대한 자세하게 작성해주세요.

* 문제 해결을 위해 어떤 시도를 해보았는지 구체적으로 함께 알려주세요.


from selenium import webdriver

from selenium.webdriver.chrome.service import Service

from selenium.webdriver.chrome.options import Options

from selenium.webdriver.common.by import By

from webdriver_manager.chrome import ChromeDriverManager

import time


chrome_options = Options()

# chrome_options.add_argument("--headless") # 크롬 열지 않고 코드 실행하기

chrome_options.add_experimental_option("excludeSwitches", ['enable-logging'])


# 셀레니움으로 웹브라우저 자동 띄우기

service = Service(executable_path=ChromeDriverManager().install())

driver = webdriver.Chrome(service=service, options=chrome_options)


# 주소의 위치로 이동

keyword = '애플'

driver.get(f"https://www.google.com/search?q={keyword}+주식")


name = driver.find_element(By.CLASS_NAME, 'DoxwDb').text

price = driver.find_element(By.CLASS_NAME, 'IsqQVc').text

high_price = driver.find_element(By.CSS_SELECTOR, 'div[data-attrid="최고"]').text

low_price = driver.find_element(By.CSS_SELECTOR, 'div[data-attrid="최저"]').text


# print(name, price, high_price, low_price)

print(f"{keyword} 주식 정보 수집 완료")

print(f"주식명: {name}")

print(f"현재가: {price}")

print(f"최고가: {high_price}")

print(f"최저가: {low_price}\n")


driver.quit()


저는 왜 최고가와 최저가가 안뜨는걸까요??

스파르타 즉문즉답







취소
 공유
취소
댓글 0
댓글 알림
나의얼굴