没有错误,但无法从网站查看JSON数据

kdfy810k  于 2023-08-08  发布在  其他
关注(0)|答案(1)|浏览(97)

我试图从网站上得到的股票价值突出显示在框中的截图,但我写的代码没有显示任何输出。
感谢帮助获取红框中的数据。
截图:https://i.imgur.com/mHXpIYw.png
网址:https://marketsmithindia.com/mstool/eval/tvssrichak/evaluation.jsp#/
JSON:https://msi-gcloud-prod.appspot.com/gateway/simple-api/ms-india/instr/0/3023210/symboldetails.json?s=20180719&e=20230719&text=TVSSRICHAK&lang=en&isConsolidated=0&ms-auth=3990+MarketSmithINDUID-Web0000000000+MarketSmithINDUID-Web0000000000+0+230325200706+-514613229
Stocklist.txt:

TVSSRICHAK
INFY
SUZLON

字符串
代码:

# -*- coding: utf-8 -*-
"""
Created on Sat Dec 24 23:14:57 2022

@author: eruku
"""

import requests

infile = 'c:/Users/eruku/Documents/StocksList.txt'
outfile = 'c:/Users/eruku/Documents/Marketsmithindia.txt'

timeout = 10
headers = {
    'User-Agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:73.0) '
    'Gecko/20100101 Firefox/73.0'
}
baseurl = 'https://msi-gcloud-prod.appspot.com/gateway/simple-api/ms-india/instr/0/3023210/symboldetails.json?s=20180719&e=20230719&text='
endurl = '&lang=en&isConsolidated=0&ms-auth=3990+MarketSmithINDUID-Web0000000000+MarketSmithINDUID-Web0000000000+0+230325200706+-514613229'
session = requests.Session()

response = session.get(baseurl, headers=headers, timeout=timeout)

with open(infile, 'r') as IN, open(outfile, 'w') as OUT:
    for stock in IN:
        stock = stock.strip()
        response = session.get(
            # f'{baseurl}api/quote-equity?symbol={stock}',
            f'{baseurl}{stock}{endurl}',
            headers=headers,
            timeout=timeout
        )
        response = response.json()

wr98u20j

wr98u20j1#

这里有一个方法来获取这些信息:

import pandas as pd
import requests
headers = {
    "User-Agent": "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/103.0.0.0 Safari/537.36"
}
url = 'https://msi-gcloud-prod.appspot.com/gateway/simple-api/ms-india/instr/0/3023210/symboldetails.json?s=20180719&e=20230719&text=TVSSRICHAK&lang=en&isConsolidated=0&ms-auth=3990+MarketSmithINDUID-Web0000000000+MarketSmithINDUID-Web0000000000+0+230325200706+-514613229'
r = requests.get(url, headers=headers)
df = pd.json_normalize(r.json()['response']['quarterlySalesAndEarningsInternational']['quarterlySalesAndEarningsOrigin'])
print(df)

字符串
终端结果:

calendarDate    sales   fiscalDate  eps salesPct    roe epsPct  totSharesHeldByFunds    isNegEPSComparison  isNonRecurring  osid    prdYear noOfFunds   quarterFlag actual  atMargin    peLow   peHigh
0   1680246000000   647.25  1680246000000   28.63   1.0 None    208.0   115235  0   0   3023210 Mar-23  45  1   1   -32767  None    None
1   1672473600000   699.43  1672473600000   20.84   6.0 None    70.0    110427  0   0   3023210 Dec-22  46  1   1   -32767  None    None
2   1664521200000   805.17  1664521200000   46.77   21.0    None    44.0    109672  0   0   3023210 Sep-22  43  1   1   -32767  None    None
3   1656572400000   713.54  1656572400000   -4.65   50.0    None    -1703.0 146257  0   0   3023210 Jun-22  45  1   1   -32767  None    None
4   1648710000000   641.94  1648710000000   9.29    10.0    None    -79.0   162903  0   0   3023210 Mar-22  49  1   1   -32767  None    None
5   1640937600000   659.01  1640937600000   12.26   19.0    None    -73.0   199768  0   0   3023210 Dec-21  53  1   1   -32767  None    None
6   1632985200000   668.02  1632985200000   32.45   25.0    None    -37.0   227130  0   0   3023210 Sep-21  56  1   1   -32767  None    None
7   1625036400000   476.02  1625036400000   0.29    131.0   None    101.0   378082  1   0   3023210 Jun-21  57  1   1   -32767  None    None
8   1617174000000   581.04  1617174000000   44.54   39.0    None    39.0    517050  0   0   3023210 Mar-21  51  1   1   -32767  None    None
9   1609401600000   553.31  1609401600000   45.27   11.0    None    159.0   565987  0   0   3023210 Dec-20  47  1   1   -32767  None    None
10  1601449200000   535.01  1601449200000   51.46   -2.0    None    95.0    499557  0   0   3023210 Sep-20  32  1   1   -32767  None    None
11  1593500400000   206.47  1593500400000   -46.24  -65.0   None    -235.0  528663  0   0   3023210 Jun-20  34  1   1   -32767  None    None
12  1585638000000   417.14  1585638000000   32.00   -28.0   None    53.0    544742  0   0   3023210 Mar-20  36  1   1   -32767  None    None
13  1577779200000   497.54  1577779200000   17.49   -15.0   None    -43.0   555153  0   0   3023210 Dec-19  36  1   1   -32767  None    None
14  1569826800000   545.11  1569826800000   26.45   -14.0   None    -31.0   545600  0   0   3023210 Sep-19  39  1   1   -32767  None    None
15  1561878000000   592.45  1561878000000   34.28   NaN None    NaN 543217  0   0   3023210 Jun-19  43  1   1   -32767  None    None
16  1554015600000   579.89  1554015600000   20.93   NaN None    NaN 574305  0   0   3023210 Mar-19  40  1   1   -32767  None    None
17  1546243200000   582.30  1546243200000   30.81   NaN None    NaN 624010  0   0   3023210 Dec-18  38  1   1   -32767  None    None
18  1538290800000   631.76  1538290800000   38.61   NaN None    NaN 617240  0   0   3023210 Sep-18  38  1   1   -32767  None    None


你可以使用json数据,我刚刚举例说明了quarterlySalesAndEarningsOrigin。参见pandasRequests的文档。

相关问题