-
Notifications
You must be signed in to change notification settings - Fork 36
/
Copy pathrealtime_get_ccs.py
72 lines (57 loc) · 3.36 KB
/
realtime_get_ccs.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
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
import requests
cookies = {
'xq_a_token': '385b836a045da45667afda72237fc969313f56f0',
}
headers = {
'User-Agent': 'Mozilla/5.0 (Windows NT 6.1; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/61.0.3163.100 Safari/537.36',
}
#
# proxys = {
# "http": "socks5://127.0.0.1:1080",
# "https": "socks5://127.0.0.1:1080",
# }
import pandas as pd
import pymysql
import os
from datetime import date
today = date.today().strftime('%Y%m%d')
# today = "20190111"
base_path = os.path.join(os.path.dirname(os.path.abspath(__file__)), "data", "xueqiu", "ccs", today)
if not os.path.exists(base_path):
os.mkdir(base_path)
mysql_cn= pymysql.connect(host='localhost', port=3306, user='quant', passwd='123456', db='quant', charset='utf8')
sql = "select id, biz_date, code, name from stock_ccs where biz_date = '2017-09-29' order by code"
df = pd.read_sql(sql, mysql_cn, index_col="id")
code_list = list(df['code'])
# code_list = ['ABAC', 'ACH', 'ALN', 'AMCN', 'ATAI', 'ATHM', 'ATV', 'AXN', 'BABA', 'BCACU', 'BEDU', 'BGNE', 'BIDU', 'BITA', 'BORN', 'BRQS', 'BSPM', 'BSTI', 'BYSI', 'BZUN', 'CAAS', 'CADC', 'CALI', 'CBAK', 'CBPO', 'CCCL', 'CCCR', 'CCIH', 'CCM', 'CCRC', 'CEA', 'CEO', 'CGA', 'CHA', 'CHL', 'CHNR', 'CHU', 'CIFS', 'CJJD', 'CLDC', 'CLNT', 'CLWT', 'CMCM', 'CNET', 'CNIT', 'CNTF', 'CO', 'COE', 'CPHI', 'CREG', 'CSIQ', 'CTRP', 'CXDC', 'CYD', 'CYOU', 'DELT', 'DL', 'DQ', 'DSWL', 'EDU', 'EHIC', 'EVK', 'FANH', 'FENG', 'FFHL', 'FORK', 'FTFT', 'GDS', 'GSH', 'GSUM', 'GURE', 'HCM', 'HEBT', 'HGSH', 'HIMX', 'HLG', 'HNP', 'HOLI', 'HPJ', 'HQCL', 'HTHT', 'JASO', 'JD', 'JKS', 'JMEI', 'JMU', 'JOBS', 'JP', 'JRJC', 'KANG', 'KGJI', 'KNDI', 'KONE', 'LEJU', 'LFC', 'LITB', 'LLIT', 'MARK', 'MLCO', 'MOMO', 'MOXC', 'NCTY', 'NEWA', 'NFEC', 'NOAH', 'NQ', 'NTES', 'NTP', 'OIIM', 'ONP', 'OSN', 'PETZ', 'PME', 'PTR', 'RCON', 'RENN', 'RYB', 'SECO', 'SEED', 'SFUN', 'SGOC', 'SHI', 'SIMO', 'SINA', 'SINO', 'SKYS', 'SMI', 'SNP', 'SOHU', 'SOL', 'SORL', 'SPI', 'SSC', 'SSW', 'SVA', 'SVM', 'SYMX', 'TAL', 'TANH', 'TEDU', 'TOUR', 'TYHT', 'UTSI', 'VIPS', 'VNET', 'WB', 'WBAI', 'WINS', 'WUBA', 'XIN', 'XNET', 'XNY', 'XRF', 'YGE', 'YIN', 'YRD', 'YY', 'ZKIN', 'ZLAB', 'ZNH', 'ZPIN', 'ZTO', 'ZX']
print(code_list)
print(len(code_list))
import json
j = 0
count = 0
param = []
for code in code_list:
count += 1
param.append(code[:-2])
# param.append(code)
if count == 50:
param_str = ','.join(param)
param = []
count = 0
j += 1
result = requests.get("https://xueqiu.com/v4/stock/quote.json?code=" + param_str, cookies=cookies, headers=headers)
# result = requests.get("https://xueqiu.com/v4/stock/quote.json?code=" + param_str, cookies=cookies, headers=headers, proxies=proxys)
# print(result.headers)
content = result.content.decode(encoding="UTF-8")
print(content)
with open(os.path.join(base_path, str(j) + '.json'), 'wb') as f:
f.write(content.encode('utf-8'))
param_str = ','.join(param)
j += 1
result = requests.get("https://xueqiu.com/v4/stock/quote.json?code=" + param_str, cookies=cookies, headers=headers)
# result = requests.get("https://xueqiu.com/v4/stock/quote.json?code=" + param_str, cookies=cookies, headers=headers, proxies=proxys)
# print(result.headers)
content = result.content.decode(encoding="UTF-8")
print(content)
with open(os.path.join(base_path, str(j) + '.json'), 'wb') as f:
f.write(content.encode('utf-8'))