1. 程式人生 > >Python 獲取新浪財經資料的案例

Python 獲取新浪財經資料的案例

data_info = {'num':'200',#股票數目
          'sort':'r3_net', #散戶資金流入
          'asc':'0',
          'bankuai':'',
           'shichang':''}
data = urllib.urlencode(data_info)          #格式化資料 
 
data = urllib2.urlopen(url = u"http://vip.stock.finance.sina.com.cn/quotes_service/api/json_v2.php/MoneyFlow.ssl_bkzj_ssggzj?page=1",
                         data = data)
 data_in = data.read()[1:-2] 
 data_formt = data_in.split('},')
 for respCmtJson in data_formt:
     respCmtJson_1 = respCmtJson+'}'
     respCmt = re.sub(r"(,?)(\w+?)\s*?:", r"\1'\2':",respCmtJson_1)  
     respCmt = respCmt.replace("'", "\"")
     resp = respCmt.decode('iso-8859-2').encode('utf-8')
     js = json.loads(resp)