- android - 多次调用 OnPrimaryClipChangedListener
- android - 无法更新 RecyclerView 中的 TextView 字段
- android.database.CursorIndexOutOfBoundsException : Index 0 requested, 光标大小为 0
- android - 使用 AppCompat 时,我们是否需要明确指定其 UI 组件(Spinner、EditText)颜色
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')
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)) for t in indo]
时,输出如下,这也是错误的,所有字符串均由字母和数字分隔:
{
"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"
},
如何在 Flask 中正确显示所有 10 个结果?是json格式
最佳答案
您需要将列表格式转换为
indo = ['abc','123','cde','efg','112','123']
到 [['abc','123' ],['cde','efg'],['112','123']]
对于您的示例,只需添加即可更改
indo = indo.xpath('//table[@id="top-gainer"]//td/text()')
indo = [indo[n:n+8] for n in range(0, len(indo), 8)]
关于python: jsonify 仅显示一个输出,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/48927600/
我目前正在尝试将一个项目从flask迁移到Django作为练习,只是为了让它在Django上工作......我想知道Django中是否有一种方法可以执行flask.jsonify的工作? 如果没有,您
我想做的是通过 AJAX 将 Python 函数的结果返回到我的 javascript。目前我得到 This Response当我期待“True”或“False”时 jquery: var tes
我对 Flask 和 Python 非常陌生,我必须将 MySql 查询转换为 json 格式。在转换时,我面临值(value)错误并且无法理解,请帮助我,提前谢谢。 ValueError:字典更新序
我目前有以下内容: class MainError: def __init__(self, code, message, errorsList): self.code = co
json 中有 10 个输出,但仅显示第一个输出。如何显示所有 10 个输出? from collections import OrderedDict import requests from lxm
我正在尝试将排序字典传递给 jsonify() 函数,然后在 JS 代码中使用它来取出值。我看到的是,即使我传递了正确的值,由于某种原因它们被 jsonify 重新排序。 json_data = {
json_data2 = some_func(DB, pra1) data = jsonify(result = json_data2) 我想将“数据”转换为字符串变量,有方便的方法吗? 最佳答案 R
我正在构建以字符串格式发送回结果的 API。 @app.route('/', methods=['POST']) def converter(): content = request.json
这是我的数据库表架构 电影(id、电影名称、流派、时间、 channel ) 我有一个 MySQL 表,想要将嵌套的 json 返回到 API,并按流派和 channel 对它们进行分组。 例如: [
我的第一个问题在这里! 我正在使用 python 和 flask 开发网络服务。 Neo4j 是我想要 APIfy 的后端。 我在图形数据库上运行一个匹配查询并想要返回一个 json 对象。下面是代码
第一次使用 Flask,我创建了一个非常基本的应用程序,我正在尝试打印推荐系统的结果。第一组代码来 self 的 python 函数 (print_most_similar),它正在创建一个格式化字符
我有一个 jsonify 模板标签: from django.core.serializers import serialize from django.db.models.query import
我有一些具有不同属性类型的对象:String、Float、LocalDate 等等。要将此对象转换为 json String,我使用 (com.google.gson.Gson) gson.toJso
我正在尝试使用 Flask 创建一个简单的 API。我现在想返回一个字典列表,如下所示: print results # prints out [{'date': '2014-09-25 19:00
基本上,我只想对我的 sql 查询结果进行 json 编码。 x = db.session.query(User).filter_by(username = request.form['usernam
玩弄 Flask,只想打印出一些 JSON 格式的数据,但我不断收到错误消息: NameError: global name 'jsonify' is not defined from flask i
我有一个需要 jsonify 的对象列表。我查看了 flask jsonify 文档,但我就是不明白。 我的类(class)有几个 inst-var,每个都是一个字符串:gene_id、gene_sy
我正在使用 Flask 蓝图模块为我的应用程序创建 REST API。因为它是一个 REST api,所以每个响应都需要用 JSON 编码。目前,我必须确保以 jsonfify(my_data) 结束
在尝试处理 Flask Rest API 中的错误时,我想返回错误消息和状态代码的 json 版本。我尝试了以下 @app.route("/model/test/",methods=["GET"])
这是我在 Persistent 中的模型: Tip text Text created_at UTCTime updated_at UTCTime title Text
我是一名优秀的程序员,十分优秀!