!pip install yfinance
import yfinance as yf
stock = yf.Ticker("AAPL")  # 替换为股票代码
print(stock.history(period="6mo"))  # 获取一天的数据


                                 Open        High         Low       Close  \

Date
2024-07-15 00:00:00-04:00 235.947003 236.695312 232.564644 233.871689
2024-07-16 00:00:00-04:00 234.470328 235.737470 231.806348 234.290741
2024-07-17 00:00:00-04:00 228.932843 230.938323 226.129179 228.364136
2024-07-18 00:00:00-04:00 229.760986 229.920629 221.769045 223.674728
2024-07-19 00:00:00-04:00 224.313288 226.288821 222.776751 223.804428
... ... ... ... ...
2025-01-07 00:00:00-05:00 242.979996 245.550003 241.350006 242.210007
2025-01-08 00:00:00-05:00 241.919998 243.710007 240.050003 242.699997
2025-01-10 00:00:00-05:00 240.009995 240.160004 233.000000 236.850006
2025-01-13 00:00:00-05:00 233.529999 234.669998 229.720001 234.399994
2025-01-14 00:00:00-05:00 234.750000 236.119995 232.472000 233.279999

                         Volume  Dividends  Stock Splits  

Date
2024-07-15 00:00:00-04:00 62631300 0.0 0.0
2024-07-16 00:00:00-04:00 43234300 0.0 0.0
2024-07-17 00:00:00-04:00 57345900 0.0 0.0
2024-07-18 00:00:00-04:00 66034600 0.0 0.0
2024-07-19 00:00:00-04:00 49151500 0.0 0.0
... ... ... ...
2025-01-07 00:00:00-05:00 40856000 0.0 0.0
2025-01-08 00:00:00-05:00 37628900 0.0 0.0
2025-01-10 00:00:00-05:00 61710900 0.0 0.0
2025-01-13 00:00:00-05:00 49630700 0.0 0.0
2025-01-14 00:00:00-05:00 38863097 0.0 0.0

[127 rows x 7 columns]