2016-12-29 98 views
-3

我过滤该标签 与 数据= soup.findAll( 'DIV',{ 'ID': 'responseDiv'}) 和得到这个。从BeautifulSoup结果提取的数据集

{ “有效”: “真”, “isinCode”:空, “lastUpdateTime”: “29-DEC-2016 12点19分23秒”, “ocLink”:“/ marketinfo/sym_map/symbolMapping.jsp?符号= NIFTY &仪器= - &日期= - & segmentLink = 17 &符号计数= 2" , “tradedDate”: “29DEC2016”, “数据”:[{ “变化”: “18.65”, “sellPrice1”: “8,050.90” “buyQuantity3”: “75”, “sellPrice2”: “8,050.95”, “buyQuantity4”: “225”, “buyQuantity1”: “750”, “LTP”: “ - ”, “buyQuantity2”: “150”,” sellPrice5 “:” 8,051.15" , “sellPrice3”: “8,051.00”, “buyQuantity5”: “675”, “sellPrice4”: “8,051.05”, “下面的”: “NIFTY”, “bestSell”: “ - ”, “annualisedVolatility” “16.61”, “optionType”: “ - ”, “prevClose”: “8,031.35”, “pChange”: “0.23”, “lastPrice”: “8,050.00”, “lowPrice”: “8,025.00”, “strikePrice”:” - “ ”premiumTurnover“: ” - “, ”numberOfContractsTraded“: ”54112“, ”underlyingValue“: ”8,055.20“,” 开放利息“:”1,03,46,700“,”隐含波动率“:” - “,”vwap“:”8,046.98“,”totalBuyQuantity“:”5,20,350“,”openPrice“:”8,028.00“,”closePrice“ : “0.00”, “百思买”: “ - ”, “changeinOpenInterest”: “ - 2,11,050”, “clientWisePositionLimits”: “29320076”, “totalSellQuantity”: “9,75,675”, “dailyVolatility”: “0.87”, “sellQuantity5”: “225”, “marketLot”: “75”, “expiryDate”: “29DEC2016”, “marketWidePositionLimits”: “ - ”, “sellQuantity2”: “150”, “sellQuantity1”: “75”,“buyPrice1 “:” 8,050.00" , “sellQuantity4”: “150”, “buyPrice2”: “8,049.80”, “sellQuantity3”: “450”, “buyPrice4”: “8,049.30”, “buyPrice3”: “8,049.35”, “buyPrice5”: “8,049.15”, “turnoverinRsLakhs”: “3,26,578.64”, “pchangeinOpenInterest”: “ - 2.00”, “settlementPrice”: “8031.35”, “instrumentType”: “FUTIDX”, “highPrice”: “8,060.00”}],” companyName“:”Nifty 50“,”eqLink“:”“}

]

我想提取粗体文本。我只是将整个事情转换为字符串并通过索引调用。我相信有一个正确的方法来转换结果集

回答

0

您的问题有点不清楚,需要编辑,但该响应看起来像json。你可以用

import json 

... 
data = soup.findAll('div',{'id':'responseDiv'}) 

加载它,假设你真的从findAll得到的是与包含JSON文本元素的列表。

extracted = json.loads(data[0].getText()) 
print(extracted['data'][0]['vwap']) 

8,046.98

的 'VWAP' 你正在试图提取例如可以像访问。 extracted是一个字典,其中包含关键字'data'的列表,该列表中的第0个元素是一个字典,其中包含关键字'vwap'的信息。