-
Notifications
You must be signed in to change notification settings - Fork 0
/
getData.py
40 lines (34 loc) · 1.03 KB
/
getData.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
# Get some yahoo finance yays
import urllib2
from BeautifulSoup import BeautifulSoup
def spList():
file = open("S+P.txt")
tickers = list()
while 1:
line = file.readline()
if not line:
break
tickers.append(line.strip())
file.close()
return tickers
if __name__ == "__main__":
tickerList = spList()
for ticker in tickerList:
print ticker
url = "http://ichart.finance.yahoo.com/table.csv?s="+ticker+"&a=00&b=1&c=1980&d=11&e=7&f=2010&g=d&ignore=.csv"
data = urllib2.urlopen(url)
url2 = "http://finance.yahoo.com/q/ks?s="+ticker+"+Key+Statistics"
page = urllib2.urlopen(url2)
soup = BeautifulSoup(page)
tags = soup.findAll("td", "yfnc_tabledata1")
beta = tags[31].text
file = open("data/"+ticker+'.csv', 'w')
file.write(beta + "\n")
file.write(data.read())
file.close()
# Get S&P 500 Index historical data
ticker = "^GSPC"
url = "http://ichart.finance.yahoo.com/table.csv?s="+ticker+"&a=00&b=1&c=1980&d=11&e=7&f=2010&g=d&ignore=.csv"
file = open("data/S+P.csv", 'w')
file.write(data.read())
file.close()