Guidelines

S&P 500 μ§€μˆ˜μ™€ κ΄€λ ¨ 데이터 μ‹€μ‹œκ°„μœΌλ‘œ μΆ”μΆœν•˜κΈ°

이번 μˆ˜μ—…μ—μ„œλŠ” Yahoo Financeμ—μ„œ S&P 500 주식 데이터λ₯Ό μΆ”μΆœν•˜λŠ” 방법을 μ•Œμ•„λ³΄κ² μŠ΅λ‹ˆλ‹€.


1. ν˜„μž¬κ°€ κ°€μ Έμ˜€κΈ°

find_elementγ„Ήλ‘œ ν˜„μž¬κ°€ κ°€μ Έμ˜€κΈ°
current_price_element = driver.find_element(By.XPATH, "//div[contains(@class, 'price')]//fin-streamer[contains(@class, 'livePrice')]//span") current_price = current_price_element.text

find_element()λŠ” νŽ˜μ΄μ§€μ—μ„œ νŠΉμ • μš”μ†Œλ₯Ό μ°ΎμŠ΅λ‹ˆλ‹€.

XPATH둜 μ •μ˜λœ λ‚΄μš©μ€ λ‹€μŒκ³Ό κ°™μŠ΅λ‹ˆλ‹€.

  • div[contains(@class, 'price')] : div νƒœκ·Έ 쀑 price 클래슀λ₯Ό ν¬ν•¨ν•˜λŠ” μš”μ†Œ

  • fin-streamer[contains(@class, 'livePrice')] : fin-streamer νƒœκ·Έ 쀑 livePrice 클래슀λ₯Ό ν¬ν•¨ν•˜λŠ” μš”μ†Œ

  • span : span νƒœκ·Έ

즉 XPATHλŠ” div νƒœκ·Έ 쀑 price 클래슀λ₯Ό ν¬ν•¨ν•˜κ³ , fin-streamer νƒœκ·Έ 쀑 livePrice 클래슀λ₯Ό ν¬ν•¨ν•˜λ©°, span νƒœκ·ΈμΈ μš”μ†Œλ₯Ό μ„ νƒν•©λ‹ˆλ‹€.


2. Previous Close κ°’ κ°€μ Έμ˜€κΈ°

Previous Close κ°’ κ°€μ Έμ˜€κΈ°
previous_close_element = wait.until(EC.presence_of_element_located((By.CSS_SELECTOR, 'fin-streamer[data-field="regularMarketPreviousClose"]'))) previous_close = previous_close_element.text

By.CSS_SELECTORλŠ” CSS μ„ νƒμžλ₯Ό μ‚¬μš©ν•˜μ—¬ data-field="regularMarketPreviousClose" 속성을 가진 fin-streamer νƒœκ·Έλ₯Ό μ„ νƒν•©λ‹ˆλ‹€.

XPATH둜 μ •μ˜λœ λ‚΄μš©μ€ λ‹€μŒκ³Ό κ°™μŠ΅λ‹ˆλ‹€.

  • fin-streamer[data-field="regularMarketPreviousClose"] : fin-streamer νƒœκ·Έ 쀑 data-field="regularMarketPreviousClose" 속성을 가진 μš”μ†Œ

previous_close_elementμ—λŠ” Previous Close 값을 가진 μš”μ†Œκ°€ μ €μž₯λ©λ‹ˆλ‹€.

previous_close_element.textλŠ” Previous Close 값을 ν…μŠ€νŠΈλ‘œ κ°€μ Έμ˜΅λ‹ˆλ‹€.


3. Volume κ°’ κ°€μ Έμ˜€κΈ°

Volume κ°’ κ°€μ Έμ˜€κΈ°
volume_element = wait.until(EC.presence_of_element_located((By.CSS_SELECTOR, 'fin-streamer[data-field="regularMarketVolume"]'))) volume = volume_element.text

data-field="regularMarketVolume" 속성을 가진 fin-streamer νƒœκ·Έλ₯Ό μ„ νƒν•˜μ—¬ Volume 값을 κ°€μ Έμ˜΅λ‹ˆλ‹€.

volume_element.textλŠ” Volume 값을 ν…μŠ€νŠΈλ‘œ κ°€μ Έμ˜΅λ‹ˆλ‹€.

Guidelines

AI Tutor

Publish

Design

Upload

Notes

Favorites

Help

Code Editor

Run
Generate

Execution Result