【问题标题】:Reading raw json data of a table into df table?将表的原始json数据读入df表?
【发布时间】:2020-05-29 00:37:57
【问题描述】:

我正在尝试将 json 数据从以下位置下载到 df 表中:“http://emweb.securities.eastmoney.com/NewFinanceAnalysis/lrbAjax?companyType=4&reportDateType=0&reportType=1&endDate=&code=SZ002475” ,即本页底部表格“http://emweb.securities.eastmoney.com/NewFinanceAnalysis/Index?type=web&code=SZ002475#”的原始数据

json 页面看起来是简单的 json 数据,如"[{\"SECURITYCODE\":\"002475.SZ\",\"REPORTTYPE\":\"1\",\"TYPE\":\" 4\",\"REPORTDATE\":\"2019/9/30 0:00:00\",\"TOTALOPERATEREVE\":\"37836138416.35\",\"OPERATEREVE\":\"37836138416.35\",. .......”

但是,以下代码没有返回任何内容:

url ="http://emweb.securities.eastmoney.com/NewFinanceAnalysis/lrbAjax?companyType=4&reportDateType=0&reportType=1&endDate=&code=SZ002475"
df = pd.read_json(url) 
print(df)

【问题讨论】:

    标签: python html json pandas dataframe


    【解决方案1】:

    使用给定的 URL。

    import pandas as pd
    import requests
    
    url="http://emweb.securities.eastmoney.com/NewFinanceAnalysis/lrbAjax?companyType=4&reportDateType=0&reportType=1&endDate=&code=SZ002475"
    json_data = requests.get(url).json()
    out_df = pd.DataFrame(eval(json_data))
    print(out_df)
    

    它正在工作,请看下面的截图

    【讨论】:

    • 谢谢。我试过了,但没有工作。而且,我更新了代码中的 URL。请看一下:)
    猜你喜欢
    • 2019-07-25
    • 1970-01-01
    • 2021-01-01
    • 2016-02-02
    • 2015-12-30
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2021-08-23
    相关资源
    最近更新 更多