之前的接的一个单,客户要抓取开盘拉app的股票数据,话不多说,点开行情->个股,如图所示
对应的数据包如图所示接下来使用python模拟请求,代码如下
import requests
import time
import re
headers = {
'users-Agent': 'Dalvik/2.1.0 (Linux; U; Android 5.1.1; HD1910 Build/LMY48Z)',
}
url = 'https://xxxxxxxxp'
datas = {
'st': '34',
'Order': '1',
'apiv': 'w28',
'Type': '1',
'DeviceID': 'ffffffff-a05e-f5e5-ffff-ffffc6851f29',
}
r = requests.post(url,headers=headers,data=datas)
但是发现原app有很多,打印其长度输出来的数据只有34条,那是不是只要改变st这个值就行,话不多说,直接上100000,通过对比原app数据即获取了全部数据。最后客户要获取价格,涨幅,主力净额,板块等信息并将其弄成其方便导入的格式,部分代码如下
import requests
import time
import re
headers = {
'users-Agent': 'Dalvik/2.1.0 (Linux; U; Android 5.1.1; HD1910 Build/LMY48Z)',
}
url = 'https://xxxxx'
datas = {
'st': '1000000',
'Order': '1',
'apiv': 'w28',
'Type': '1',
'DeviceID': 'ffffffff-a05e-f5e5-ffff-ffffc6851f29',
}
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')
点击此处登录后即可评论