야후 파이낸스에서 일봉정보를 크롤링해 봅시다.
import requests
import datetime as pydatetime
import time
import datetime
import json
url = "https://apidojo-yahoo-finance-v1.p.rapidapi.com/stock/v2/get-historical-data"
toDate = datetime.date.today()
fromDate = toDate - datetime.timedelta(days=10)
# print (fromDate.__format__("%Y-%m-%d"))
# print (str(toDate))
fromdateTimestamp = (datetime.datetime.strptime(str(fromDate), "%Y-%m-%d").timestamp())
todateTimestamp = (datetime.datetime.strptime(str(toDate), "%Y-%m-%d").timestamp())
szFromtDate = str(fromdateTimestamp).replace(".0","")
szToDate = str(todateTimestamp).replace(".0","")
szSearhItem = "020150.KS" #일진머트리얼즈 "019170.KS" #신풍제약 "011930.KS" #신성이엔지
querystring = {"frequency":"1d","filter":"history","period1":szFromtDate,"period2":szToDate,"symbol":szSearhItem}
# print (querystring)
headers = {
'x-rapidapi-host': "apidojo-yahoo-finance-v1.p.rapidapi.com",
'x-rapidapi-key': "insert api key"
}
response = requests.request("GET", url, headers=headers, params=querystring)
# print(response.text)
str_list = []
data = json.loads(response.text)
#print (data["prices"])
for item in data["prices"]:
str_list.append( datetime.datetime.fromtimestamp(item["date"]).strftime("%Y-%m-%d"))
str_list.append("일 => ")
str_list.append(item["close"])
str_list.append(" 원\n")
print("".join(str(v) for v in str_list))
끝~
'개발 > python' 카테고리의 다른 글
[python 기초] 엑셀에 구구단 출력하기 (0) | 2021.01.05 |
---|---|
파이썬 - pandas LG전자 일봉가져오기 (0) | 2020.12.29 |
python - 다음 일봉 크롤링 (0) | 2020.12.19 |