import urllib
import time
import pandas as pd
n = 001747
s = 0
wurl = 'http://fund.eastmoney.com/f10/tsdata_'
filename = 'sharp.txt'
data = pd.read_excel('834_4_5.xlsx', header=0)
def save_data(i,n):
i = str(i).zfill(6)
url = wurl + str(i) + '.html'
print url
content = urllib.urlopen(url).read().decode('utf-8')
time.sleep(2)
head = ("夏普比率").decode('utf-8')
tail = ("</tr>").decode('utf-8')
ph = content.find(head)
ph1 = content.find('num',ph)
pj1 = content.find('<',ph1)
num1 = content[ph1+5:pj1]
print num1
ph2 = content.find('num',pj1)
pj2 = content.find('<',ph2)
num2 = content[ph2+5:pj2]
print num2
ph3 = content.find('num',pj2)
pj3 = content.find('<',ph3)
num3 = content[ph3+5:pj3]
print num3
if i == n:
f.write(str(i)+','+num1+','+num2+','+num3)
else:
f.write(str(i)+','+num1+','+num2+','+num3+'\n')
with open(filename,'w') as f:
for c in data['FundClassID']:
c = c-202000000000
if c != s:
save_data(c,n)
s = c