同花顺的一个爬虫 可以获取前后复权因子

https://github.com/rainx/pytdx/issues/20 via yutiansut

import requests
import pandas as pd
import numpy as np

# 00 不复权 01前复权 02后复权

def get_k_data_year(code,year,if_fq):
    data_=[]


    url='http://d.10jqka.com.cn/v2/line/hs_%s/%s/%s.js'%(str(code),str(if_fq),str(year))
    for item in requests.get(url).text.split('\"')[3].split(';'):
        data_.append(item.split(','))
    return pd.DataFrame(data_,index=list(np.asarray(data_).T[0]),columns=['date','open','high','low','close','volume','amount','factor'])


if __name__=='__main__':
    print(get_k_data_year('000001','2016','01'))
    print(get_k_data_year(600010,2016,'01'))
date  open  high   low close     volume         amount factor
20160104  20160104  9.72  9.74  9.07  9.16   56349787   660376150.00  0.573
20160105  20160105  9.11  9.36  9.01  9.22   66326995   755531350.00  0.674
20160106  20160106  9.23  9.35  9.21  9.32   51570644   591698520.00  0.524
20160107  20160107  9.22  9.22  8.81  8.83   17476110   194869490.00  0.178
20160108  20160108  9.06  9.12  8.80  8.98   74752758   831334540.00  0.760
20160111  20160111  8.88  8.95  8.62  8.68   73201399   800683640.00  0.744
20160112  20160112  8.74  8.81  8.58  8.72   56164230   605970830.00  0.571
20160113  20160113  8.79  8.83  8.63  8.64   39170948   424371690.00  0.398
20160114  20160114  8.54  8.72  8.45  8.69   66631454   708535000.00  0.677
20160115  20160115  8.60  8.72  8.40  8.43   44820214   474908140.00  0.456
20160118  20160118  8.33  8.52  8.30  8.39   42104088   439917820.00  0.428
20160119  20160119  8.42  8.70  8.39  8.64   50110908   532074700.00  0.509
20160120  20160120  8.63  8.72  8.42  8.50   60375250   640968950.00  0.614
20160121  20160121  8.45  8.67  8.32  8.32   60614511   638127880.00  0.616
20160122  20160122  8.38  8.42  8.23  8.38   46675214   482984450.00  0.475
20160125  20160125  8.38  8.42  8.32  8.36   37643172   390734880.00  0.383
20160126  20160126  8.32  8.32  7.93  7.94   64790114   653561590.00  0.659
20160127  20160127  7.99  8.03  7.72  7.95   56903705   558510640.00  0.579
20160128  20160128  7.90  7.96  7.76  7.79   30254078   296055320.00  0.308
20160129  20160129  7.83  8.12  7.79  8.05   54443576   540544460.00  0.554
20160201  20160201  8.03  8.06  7.83  7.88   41773214   412635640.00  0.425
20160202  20160202  7.88  8.07  7.87  8.01   36910416   367360500.00  0.375
20160203  20160203  7.92  7.96  7.86  7.92   27457217   269997840.00  0.279
20160204  20160204  7.96  8.05  7.95  8.01   37309947   370586190.00  0.379
20160205  20160205  8.02  8.02  7.97  7.98   27089334   269184380.00  0.275
20160215  20160215  7.77  7.92  7.76  7.87   27849946   271173370.00  0.283
20160216  20160216  7.92  8.07  7.91  8.06   42838638   427507770.00  0.436
20160217  20160217  8.07  8.23  8.04  8.17   58516706   590538920.00  0.595
20160218  20160218  8.20  8.23  8.12  8.12   40617824   412337570.00  0.413
20160219  20160219  8.12  8.17  8.04  8.08   31889825   320939650.00  0.324
...            ...   ...   ...   ...   ...        ...            ...    ...
20161121  20161121  9.02  9.12  9.01  9.08   85024326   785475680.00  0.581
20161122  20161122  9.08  9.20  9.07  9.20  118025694  1097408710.00  0.807
20161123  20161123  9.18  9.40  9.18  9.29  175286940  1660465700.00  1.198
20161124  20161124  9.28  9.36  9.26  9.31   77974884   738580570.00  0.533
20161125  20161125  9.32  9.46  9.30  9.46  101367499   968127770.00  0.693
20161128  20161128  9.53  9.62  9.44  9.47  127968924  1240686230.00  0.875
20161129  20161129  9.43  9.54  9.39  9.46   88777923   854308660.00  0.607
20161130  20161130  9.49  9.56  9.34  9.39  102596305   985758450.00  0.701
20161201  20161201  9.41  9.47  9.39  9.44   64600437   619633750.00  0.442
20161202  20161202  9.44  9.44  9.28  9.39   82968650   790044440.00  0.567
20161205  20161205  9.34  9.38  9.25  9.30   76436570   723222050.00  0.522
20161206  20161206  9.32  9.36  9.29  9.33   60290276   571585180.00  0.412
20161207  20161207  9.32  9.33  9.25  9.32   49340476   466085500.00  0.337
20161208  20161208  9.34  9.39  9.27  9.36   67145216   638058500.00  0.459
20161209  20161209  9.34  9.59  9.32  9.49  151419920  1460778300.00  1.035
20161212  20161212  9.49  9.61  9.28  9.34  125687400  1206662620.00  0.859
20161213  20161213  9.32  9.34  9.17  9.26   64577157   607769970.00  0.441
20161214  20161214  9.26  9.35  9.24  9.24   59770574   564787520.00  0.409
20161215  20161215  9.21  9.25  9.05  9.09   82761287   767751840.00  0.566
20161216  20161216  9.08  9.13  9.05  9.09   39681397   366925350.00  0.271
20161219  20161219  9.06  9.07  9.01  9.04   49401064   453899740.00  0.338
20161220  20161220  9.04  9.04  8.92  8.95   63663837   580118170.00  0.435
20161221  20161221  8.96  9.00  8.95  9.00   36992065   338201450.00  0.253
20161222  20161222  8.99  9.00  8.95  8.98   34134124   311546860.00  0.233
20161223  20161223  8.98  8.98  8.91  8.92   38291216   348140450.00  0.262
20161226  20161226  8.90  8.97  8.86  8.96   30205896   273934290.00  0.206
20161227  20161227  8.96  8.97  8.91  8.92   26884124   244788270.00  0.184
20161228  20161228  8.92  8.95  8.88  8.90   33605509   304898610.00  0.230
20161229  20161229  8.91  8.93  8.89  8.92   33875853   307183500.00  0.232
20161230  20161230  8.92  8.94  8.90  8.94   30260736   274882700.00  0.207

[244 rows x 8 columns]
           date  open  high   low close     volume        amount factor
20160104  20160104  2.59  2.59  2.32  2.33   69437299  242332010.00  0.618
20160105  20160105  2.28  2.44  2.23  2.39  114924349  378947390.00  1.022
20160106  20160106  2.41  2.61  2.37  2.59  183924160  648683940.00  1.636
20160107  20160107  2.51  2.54  2.33  2.34   51144318  173416790.00  0.455
20160108  20160108  2.41  2.57  2.34  2.54  269896420  947258110.00  2.400
20160111  20160111  2.49  2.49  2.34  2.36  196359560  661641860.00  1.746
20160112  20160112  2.36  2.39  2.24  2.31   98270625  317175040.00  0.874
20160113  20160113  2.34  2.46  2.29  2.31  125690384  417415510.00  1.118
20160114  20160114  2.23  2.39  2.21  2.35   98322435  316861960.00  0.874
20160115  20160115  2.32  2.33  2.23  2.24   93528953  297474680.00  0.832
20160118  20160118  2.23  2.27  2.20  2.24   64590691  202761380.00  0.574
20160119  20160119  2.26  2.31  2.24  2.29   96680129  307322480.00  0.860
20160120  20160120  2.26  2.34  2.24  2.26  101959509  324735300.00  0.907
20160121  20160121  2.22  2.27  2.18  2.19   87420957  272307120.00  0.778
20160122  20160122  2.22  2.26  2.16  2.24   80863272  251230110.00  0.719
20160125  20160125  2.26  2.28  2.23  2.24   63713723  201200220.00  0.567
20160126  20160126  2.22  2.24  2.02  2.09  113888133  344049080.00  1.013
20160127  20160127  2.11  2.13  2.03  2.11  103701991  302859880.00  0.922
20160128  20160128  2.08  2.09  1.90  1.92   97593135  272647830.00  0.868
20160129  20160129  1.94  2.11  1.91  2.11  197683570  572679180.00  1.758
20160201  20160201  2.09  2.10  1.96  2.01  131984720  375889720.00  1.174
20160202  20160202  1.99  2.17  1.99  2.06  108175246  315234680.00  0.962
20160203  20160203  2.04  2.06  1.99  2.02   91365909  258485030.00  0.813
20160204  20160204  2.04  2.09  2.02  2.06   83281507  240504290.00  0.741
20160205  20160205  2.08  2.09  2.02  2.03   52837897  151741470.00  0.470
20160215  20160215  1.96  2.06  1.94  2.04   58809771  164621270.00  0.523
20160216  20160216  2.03  2.10  2.01  2.09   93010401  271062480.00  0.827
20160217  20160217  2.09  2.16  2.07  2.11  115949211  342859230.00  1.031
20160218  20160218  2.13  2.15  2.09  2.11   99191116  294640880.00  0.882
20160219  20160219  2.09  2.12  2.08  2.10   58237732  170913540.00  0.518
...            ...   ...   ...   ...   ...        ...           ...    ...
20161121  20161121  2.11  2.14  2.10  2.11  114557751  339795860.00  1.019
20161122  20161122  2.11  2.15  2.11  2.14  167943830  502591470.00  1.494
20161123  20161123  2.14  2.16  2.11  2.12  101154491  301503020.00  0.900
20161124  20161124  2.11  2.14  2.11  2.12   91680268  272503710.00  0.815
20161125  20161125  2.14  2.14  2.09  2.14  172758960  512616630.00  1.536
20161128  20161128  2.14  2.16  2.12  2.14  149050060  446304570.00  1.326
20161129  20161129  2.14  2.19  2.13  2.16  285636000  869041780.00  2.540
20161130  20161130  2.15  2.16  2.11  2.13  118658206  354947140.00  1.055
20161201  20161201  2.13  2.19  2.12  2.19  187748290  569961340.00  1.670
20161202  20161202  2.19  2.21  2.16  2.16  152353480  464076130.00  1.355
20161205  20161205  2.13  2.16  2.11  2.11  117903892  351497450.00  1.049
20161206  20161206  2.12  2.13  2.10  2.11   58917294  174115600.00  0.524
20161207  20161207  2.11  2.16  2.11  2.16  156476360  469002600.00  1.392
20161208  20161208  2.16  2.16  2.11  2.11  117791919  351791910.00  1.048
20161209  20161209  2.11  2.15  2.11  2.12  115871897  343863510.00  1.031
20161212  20161212  2.14  2.16  2.05  2.06  206053250  609641440.00  1.833
20161213  20161213  2.05  2.08  2.04  2.07   83568115  241203240.00  0.743
20161214  20161214  2.07  2.07  2.01  2.03  101446171  290766760.00  0.902
20161215  20161215  2.01  2.04  2.01  2.04   55941526  158843460.00  0.498
20161216  20161216  2.03  2.04  2.01  2.04   53356473  151462500.00  0.475
20161219  20161219  2.04  2.05  2.02  2.02   55753284  158820550.00  0.496
20161220  20161220  2.03  2.03  2.00  2.01   60642763  170695500.00  0.539
20161221  20161221  2.01  2.03  2.01  2.03   70177026  198392800.00  0.624
20161222  20161222  2.02  2.03  2.01  2.01   52148443  146992360.00  0.464
20161223  20161223  2.01  2.01  1.99  2.01   51380195  144042030.00  0.457
20161226  20161226  2.00  2.01  1.98  2.01   54378359  151634810.00  0.484
20161227  20161227  2.00  2.01  1.99  2.00   29679659   83301045.00  0.264
20161228  20161228  2.01  2.01  1.99  1.99   31189281   87149698.00  0.277
20161229  20161229  1.99  2.01  1.98  1.99   31461786   87826414.00  0.280
20161230  20161230  1.99  2.00  1.98  1.99   36529644  101796632.00  0.325

[244 rows x 8 columns]

results matching ""

    No results matching ""