【问题标题】:Trouble parsing data from website into dictionary: python3无法将网站中的数据解析为字典:python3
【发布时间】:2016-08-27 04:37:07
【问题描述】:

我正在尝试解析来自股票交易网站的数据,例如对于特定股票的 URL 是

https://nseindia.com/live_market/dynaContent/live_watch/get_quote/GetQuote.jsp?symbol=SGJHL

我需要的数据在 id="responseDiv" 下(在下面提取)并且包含在子数组“data”中。虽然我可以使用 beautifulsoup 获取原始数据,但将其分解为 key:value 字典的最有效方法是什么?

我不能使用“,”,因为它会破坏包含“,”作为千位分隔符的数值。

非常感谢!

{"futLink":"","otherSeries":["EQ"],"lastUpdateTime":"26-AUG-2016 16:00:00","tradedDate":"26AUG2016",**"data":[{"extremeLossMargin":"5.00","cm_ffm":"11.65","bcStartDate":"18-SEP-15","change":"-","buyQuantity3":"-","sellPrice1":"-","buyQuantity4":"-","sellPrice2":"-","priceBand":"20","buyQuantity1":"-","deliveryQuantity":"42,643","buyQuantity2":"-","sellPrice5":"-","quantityTraded":"51,997","buyQuantity5":"-","sellPrice3":"-","sellPrice4":"-","open":"6.00","low52":"5.80","securityVar":"6.41","marketType":"N","pricebandupper":"7.20","totalTradedValue":"3.13","faceValue":"10.00","ndStartDate":"-","previousClose":"6.00","symbol":"SGJHL","varMargin":"25.98","lastPrice":"6.00","pChange":"0.00","adhocMargin":"-","companyName":"SHREE GANESH JEWELLERY HOUSE (I) LIMITED","averagePrice":"6.02","secDate":"26AUG2016","series":"EQ","isinCode":"INE553K01019","indexVar":"15.00","pricebandlower":"4.80","totalBuyQuantity":"-","high52":"13.00","purpose":"ANNUAL GENERAL MEETING","cm_adj_low_dt":"19-AUG-16","closePrice":"6.00","isExDateFlag":false,"recordDate":"-","cm_adj_high_dt":"16-OCT-15","totalSellQuantity":"-","dayHigh":"6.15","exDate":"15-SEP-15","sellQuantity5":"-","bcEndDate":"24-SEP-15","css_status_desc":"Listed","ndEndDate":"-","sellQuantity2":"-","sellQuantity1":"-","buyPrice1":"-","sellQuantity4":"-","buyPrice2":"-","sellQuantity3":"-","applicableMargin":"30.98","buyPrice4":"-","buyPrice3":"-","buyPrice5":"-","dayLow":"5.90","deliveryToTradedQuantity":"82.01","totalTradedVolume":"51,997"}]**,"optLink":""}

【问题讨论】:

  • 你能展示你用来解析这些数据的代码吗?
  • 你试过用json吗??您很可能会在这里找到答案。 stackoverflow.com/q/19483351

标签: python parsing beautifulsoup


【解决方案1】:

这似乎是一个 JSON 响应。您可以使用 JSON 库来访问这样的键值:

jsonData = json.load('YOUR RAW DATA')
print (jsonData['bcStartDate'])

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2021-05-01
    • 1970-01-01
    • 2019-04-13
    • 2018-12-09
    • 2017-01-12
    • 2021-04-11
    • 1970-01-01
    相关资源
    最近更新 更多