#-*-coding:utf-8-*-import urllib2response = Urllib2.urlopen (' http://hq.sinajs.cn/list=sh601006 ') HTML = Response.read () Print Html.decode ("GBK")
There are two ways to get the stock data now:
1. Http/javascript Interface Fetch data
2. Web-service interface
1.http/javascript Interface Fetch data
1.1Sina Stock Data Interface
Take the Great Qin Railway (stock code: 601006) For example, if you want to get its latest market, just access Sina's stock data interface:
http://hq.sinajs.cn/list=sh601006
This URL returns a string of text, for example:
var hq_str_sh601006= "Great Qin Railway, 27.55, 27.25, 26.91, 27.55, 26.20, 26.91, 26.92,
22114263, 589824680, 4695, 26.91, 57590, 26.90, 14700, 26.89, 14300,
26.88, 15100, 26.87, 3100, 26.92, 8900, 26.93, 14230, 26.94, 25150, 26.95, 15220, 26.96, 2008-01-11, 15:05:32 ";
The string is stitched together by a lot of data, with different meanings separated by commas, and the sequence number starts with 0, according to the programmer's idea.
0: "Great Qin Railway", Stock name;
1: "27.55″, open today;
2: "27.25″, yesterday close;
3: "26.91″, current price;
4: "27.55″, today's highest price;
5: "26.20″, today's lowest price;
6: "26.91″, bid price, namely" buy one "offer;
7: "26.92″, bid price, namely" sell one "offer;
8: "22114263″, the number of shares traded, as the stock trading with 100 shares as the basic unit, so when used, the value is usually divided by 100;
9: "589824680″, deal amount, unit for" Yuan ", for a glance, usually" million "for the transaction amount of units, so usually the value divided by 10,000;
10: "4695″," "Buy a" application 4695 shares, that is, 47 lot;
11: "26.91″", "buy one" offer;
12: "57590″," buy two "
13: "26.90″," buy two "
14: "14700″," buy three "
15: "26.89″," buy three "
16: "14300″," buy four "
17: "26.88″," buy four "
18: "15100″", "Buy Five"
19: "26.87″", "Buy Five"
20: "3100″," sell one "declare 3100 shares, namely 31 lot;
21: "26.92″", "sell one" offer
(22, 23), (24, 25), (26,27), (28, 29) respectively "sell two" to "sell four"
30: "2008-01-11″, date;
31: "15:05:32″, time;
An example of a simple JavaScript application:
<script type= "Text/javascript" src= "http://hq.sinajs.cn/list=sh601006" charset= "gb2312" ></script>
<script type= "Text/javascript" >var elements=hq_str_sh601006.split (",");
document.write ("Current price: +elements[3]); </script" >
This code outputs the current stock price of the Great Qin Railway (stock code: 601006)
Current price:14.20
If you want to query multiple shares at the same time, then add a comma at the end of the URL, plus the stock code on it, for example, you want to query the Da Qin Railway (601006) and Datong Coal (601001) quotes, so use the URL:
http://hq.sinajs.cn/list=sh601003,sh601001
Query the market index, for example, the Shanghai Composite Index (000001):
http://hq.sinajs.cn/list=s_sh000001
The data returned by the server is:
var hq_str_s_sh000001= "Shanghai index, 3094.668,-128.073,-3.97,436653,5458126";
Data meanings are: Index name, current point, current price, rate of rise and fall, turnover (hand), turnover (million);
Query Szse Component number:
http://hq.sinajs.cn/list=s_sz399001
Reference:
http://blog.csdn.net/simon803/article/details/7784682
Http://www.mamicode.com/info-detail-1053260.html
Http://www.361way.com/python-stock-tushare/4579.html
Python-urllib stock-data-getting