编辑代码

import requests
import time
import re

headers = {
    'users-Agent': 'Dalvik/2.1.0 (Linux; U; Android 5.1.1; HD1910 Build/LMY48Z)',

}
url = 'https://apphq.longhuvip.com/w1/api/index.php'
datas = {
    'st': '1000000',
    'Order': '1',
    'a': 'RealRankingInfo_W8',
    'c':'NewStockRanking',
    'PhoneOSNew': '1',
    'RStart':'0925',
  
    'apiv': 'w28',
    'Type': '1',
    'DeviceID': 'ffffffff-a05e-f5e5-ffff-ffffc6851f29',
    'Isst':'0',
    'Date':'',
    'Index': '0',
    'FilterMotherboard':'0',
    'Filter':'0',
    'Ratio':'6',
    'FilterTIB':'0',
    'FilterGem':'0',
    'REnd':'1500',

    
}
r = requests.post(url,headers=headers,data=datas)
data1 = r.json()['list']
print(len(data1))
print(data1)
print(len(data1))
# print(data1[0])
# # print(data1)
for j in data1:
    print(j)
    print(j[0]+':'+j[1]+' 价格:'+str(j[5])+' 涨幅:'+str(j[6])+'% {}'.format(j[23])+' 主力净额:'+str(j[13])+' 板块:'+j[4]+'\n')
    with open('200_gegu_kaipanla.txt','a+') as file:
        file.write(j[0]+':'+j[1]+' 价格:'+str(j[5])+' 涨幅:'+str(j[6])+'% {}'.format(j[23])+' 主力净额:'+str(j[13])+' 板块:'+j[4]+'\n')

    code = j[0]
    name = j[4]
    pd = j[23]
    long = j[-15]
    num = ''
    if code[0] == '3' or code[0] == '0':
        num = '0'
        hz = '.SZ'
    elif code[0] == '6':
        num = '1'
        hz = '.Sh'
    else:
        num = ''
        hz = ''
        pass


    print(num+'|'+code+hz+'|'+name)
    with open('200_gegu概念.txt', 'a+', encoding='gbk') as f1:
        f1.write(num + '|' + code + hz + '|' + name+ '\n')
    if pd.lstrip().rstrip():
        with open('200_1.txt','a+',encoding='gbk') as ff1:
            ff1.write(num + '|' +code + hz +'|'+pd.lstrip().rstrip()+'\n')
    with open('200_2.txt','a+',encoding='gbk') as f22:
        f22.write(num+'|'+code+'|'+ hz+'|'+str(j[13])+'\n')