커뮤니티
포인트
쿠폰
내 강의실
국비 신청 내역
증명서
계정
로그아웃
학습 질문
개발 일지
나의 활동
답변 완료
2-8 구글 주식 정보 크롤링 자동화
[왕초보] 칼퇴를 부르는 파이썬 업무 자동화
2주차
북마크
은*현
댓글
1
추천
0
조회수
10
조회수
10
답변 완료

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

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



  1. 수업을 듣고 있는데 중간에 변수 이름을 CLASS NAME 에서 CSS_SELECTOR 로 바꾸는데 왜 바꾸는지 모르겠습니다.
  2. 애플 주식 가격을 가져올 때, class에서 가져오는 것은 이해했는데 왜 코드 앞에 . 을 붙이는지 모르겠습니다.

price = driver.find_element(By.CSS_SELECTOR, ".IsqQVc").text



스파르타 즉문즉답





from selenium import webdriver

from selenium.webdriver.chrome.options import Options

from selenium.webdriver.common.by import By


chrome_options = Options()

chrome_options.add_experimental_option("detach", True)

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

driver = webdriver.Chrome(options=chrome_options)


keyword_list = ['애플', '삼성전자', 'SK하이닉스']

for keyword in keyword_list:

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


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

price = driver.find_element(By.CSS_SELECTOR, ".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(f"주식명: {name}")

print(f"가격: {price}")

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

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


driver.quit()



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