有的,但一直无法识别,可能是我云函数的格式有误?我对python的了解不太多,但是学校内的比赛要用到,下面代码用chatgpt做过一些修改,在debug console那里一直识别不到,麻烦您帮我看一下,谢谢
from leancloud import Engine
engine = Engine()
import requests
from leancloud import Object
class Stock(Object):
pass
def save_stock_data(request):
url = 'https://xueqiu.com/service/v5/stock/screener/quote/list?page=1&size=4432&order=desc&orderby=percent&order_by=percent&market=CN&type=sh_sz&_=1623304455997'
headers = {"User-Agent": "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/89.0.4389.90 Safari/537.36"}
# 发送网络请求
response = requests.get(url=url, headers=headers)
json_data = response.json()
i=0
# 数据筛选
data_list = json_data['data']['list']
for data in data_list:
# 建立for循环 把列表数据遍历出来
# print(data) #解析数据
# 设置data取键值对
data1 = data['symbol']
data2 = data['name']
data3 = data['current']
data4 = data['chg']
if data4:
if float(data4) > 0:
data4 = '+' + str(data4)
else:
data4 = str(data4)
data5 = data['percent']
data6 = str(data['current_year_percent']) + '%'
data7 = data['volume']
data8 = data['amount']
data9 = str(data['turnover_rate'])+'%'
data10 = data['pe_ttm']
data11 =data['dividend_yield']
if data11:
data11 = str(data['dividend_yield'])+'%'
else:
data11 = None
data12 = data['market_capital']
print(data1, data2, data3, data4, data5, data6, data7, data8, data9, data10, data11, data12,)
# 数据保存
data_dict = {'股票代码': data1, '股票名称': data2, '当前价': data3, '涨跌额': data4, '涨跌幅': data5, '年初至今': data6,
'成交量': data7, '成交额':data8, '换手率': data9, '市盈率(TTM)': data10, '股息率': data11, '市值': data12, }
i=i+1;
# 保存到云端
stock_object = Stock()
stock_object.set('ID', data1)
stock_object.set('Name',data2)
stock_object.set('PresentPrice',data3)
stock_object.set('RAF',data5)
stock_object.save() # 将对象数据保存至服务器
if(i==10):#为了方便调试设置每次只爬取十个股票
break