python:jsonify仅显示一个输出
json中有10个输出,但只显示了第一个输出。如何显示所有10个输出python:jsonify仅显示一个输出,python,json,flask,Python,Json,Flask,json中有10个输出,但只显示了第一个输出。如何显示所有10个输出 from collections import OrderedDict import requests from lxml import html @app.route('/saptop', methods=['GET']) def saptop(): page_indo = requests.get('http://www.waterfrontsekuritas.com/marketview') ind
from collections import OrderedDict
import requests
from lxml import html
@app.route('/saptop', methods=['GET'])
def saptop():
page_indo = requests.get('http://www.waterfrontsekuritas.com/marketview')
indo = html.fromstring(page_indo.content)
indo = indo.xpath('//table[@id="top-gainer"]//td/text()')
col = ['Stockcode','Lastprice','Prevprice','pc','Change','Tfreq','Vol','Value']
c1 = [OrderedDict(zip(col,indo))]
return jsonify({'Stock': c1})
电流输出仅显示第一个
{
"Stock": [
{
"Stockcode": "BOSS",
"Lastprice": "1,400",
"Prevprice": "1,120",
"pc": "25.00",
"Change": "280",
"Tfreq": "3,640",
"Vol": "23,087,100",
"Value": "29,132,765,000"
}
]
}
当更改为c1=[OrderedDict(zip(col,t))表示印度语中的t]
时,以下输出也是错误的,所有字符串由字母和数字分隔:
{
"Stock": [
{
"Stockcode": "B",
"Lastprice": "O",
"Prevprice": "S",
"pc": "S"
},
{
"Stockcode": "1",
"Lastprice": ",",
"Prevprice": "4",
"pc": "0",
"Change": "0"
},
{
"Stockcode": "1",
"Lastprice": ",",
"Prevprice": "1",
"pc": "2",
"Change": "0"
},
{
"Stockcode": "2",
"Lastprice": "5",
"Prevprice": ".",
"pc": "0",
"Change": "0"
},
如何在烧瓶中正确显示所有10个结果?它是json格式您需要将列表格式从
indo=['abc','123','cde','efg','112','123']
to
对于您的示例,只需添加更改即可
indo = indo.xpath('//table[@id="top-gainer"]//td/text()')
indo = [indo[n:n+8] for n in range(0, len(indo), 8)]