Python小試牛刀二

繼續(xù)上次的話題,今天的目的是要抓取給定公司上市一個月內(nèi)的股價。

貌似我用了比腳笨的辦法,不過不管怎么說還是成功了。代碼如下:

out = open('C:/.../fetchpriceall.txt','w') from matplotlib.finance import quotes_historical_yahoo from matplotlib.dates import YearLocator, MonthLocator, DateFormatter import datetime from datetime import date daysFmt = DateFormatter('%m-%d-%Y') set = [ ('KMI', '2011', '02', '11', '2011', '03', '11'), ...... ...... ('MWRX', '2013', '06', '27', '2013', '07', '27'), ] ticker=[q[0] for q in set] year1=[q[1] for q in set] year1=[int(i) for i in year1] month1=[q[2] for q in set] month1=[int(i) for i in month1] day1=[q[3] for q in set] day1=[int(i) for i in day1] year2=[q[4] for q in set] year2=[int(i) for i in year2] month2=[q[5] for q in set] month2=[int(i) for i in month2] day2=[q[6] for q in set] day2=[int(i) for i in day2] for j in range(len(ticker)): date1 = datetime.date( year1[j], month1[j], day1[j]) date2 = datetime.date( year2[j], month2[j], day2[j]) print(ticker[j]) try: quotes = quotes_historical_yahoo(ticker[j], date1, date2) except: continue datest = [q[0] for q in quotes] closes = [q[2] for q in quotes] closer = [round(float(i),2) for i in closes] datest = [int(i) for i in datest] dates = [date.fromordinal(i) for i in datest] for i in range(len(datest)): print(ticker[j],',',dates[i],',',closer[i], file=out) out.close()

最后編輯于
?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請聯(lián)系作者
【社區(qū)內(nèi)容提示】社區(qū)部分內(nèi)容疑似由AI輔助生成,瀏覽時請結(jié)合常識與多方信息審慎甄別。
平臺聲明:文章內(nèi)容(如有圖片或視頻亦包括在內(nèi))由作者上傳并發(fā)布,文章內(nèi)容僅代表作者本人觀點,簡書系信息發(fā)布平臺,僅提供信息存儲服務(wù)。

相關(guān)閱讀更多精彩內(nèi)容

  • 背景 一年多以前我在知乎上答了有關(guān)LeetCode的問題, 分享了一些自己做題目的經(jīng)驗。 張土汪:刷leetcod...
    土汪閱讀 12,899評論 0 33
  • **2014真題Directions:Read the following text. Choose the be...
    又是夜半驚坐起閱讀 11,041評論 0 23
  • 愛,什么是愛,為什么愛,能愛多久?這些都是X,沒有人知道確切答案,因為地球在轉(zhuǎn)動,周圍一切事物每時每刻都在發(fā)生著變...
    沉默君閱讀 574評論 0 3
  • 一天,火熱的一天 激情的六月 花的海洋, 童歌的校園, 我們難分難舍, 難忘的今天, 快樂的日子, 我們揮揮手, ...
    宏昌居士123閱讀 247評論 2 11
  • 在網(wǎng)文里幾經(jīng)輾轉(zhuǎn),最后才發(fā)現(xiàn):在別人的幻想里,我是不會找得到自己想要的真實的。 于是乎,有一天,我...
    玖蟄閱讀 395評論 0 0

友情鏈接更多精彩內(nèi)容