页面使用javascript 动态加载,但requests 不支持。
但是,您可以使用 nsetools 库。
用pip install nsetools安装它
from pprint import pprint
from nsetools import Nse
stockcode = "DISHTV"
nse = Nse()
data = nse.get_quote(stockcode)
pprint(data)
输出:
{'adhocMargin': None,
'applicableMargin': 36.65,
'averagePrice': 13.4,
'basePrice': 13.55,
'bcEndDate': None,
'bcStartDate': None,
'buyPrice1': None,
'buyPrice2': None,
'buyPrice3': None,
'buyPrice4': None,
'buyPrice5': None,
'buyQuantity1': None,
'buyQuantity2': None,
'buyQuantity3': None,
'buyQuantity4': None,
'buyQuantity5': None,
'change': '-0.05',
'closePrice': 13.45,
'cm_adj_high_dt': '21-NOV-19',
'cm_adj_low_dt': '03-APR-20',
'cm_ffm': 1238.24,
'companyName': 'Dish TV India Limited',
'css_status_desc': 'Listed',
'dayHigh': 13.65,
'dayLow': 13.25,
'deliveryQuantity': 3983661.0,
'deliveryToTradedQuantity': 77.06,
'exDate': '05-NOV-18',
'extremeLossMargin': 3.5,
'faceValue': 1.0,
'high52': 19.5,
'indexVar': None,
'isExDateFlag': False,
'isinCode': 'INE836F01026',
'lastPrice': 13.5,
'low52': 3.9,
'marketType': 'N',
'ndEndDate': None,
'ndStartDate': None,
'open': 13.5,
'pChange': '-0.37',
'previousClose': 13.55,
'priceBand': 10.0,
'pricebandlower': 12.2,
'pricebandupper': 14.9,
'purpose': 'INTERIM DIVIDEND - RE 0.50 PER SHARE',
'quantityTraded': 5169827.0,
'recordDate': '06-NOV-18',
'secDate': '09-Oct-2020 00:00:00',
'securityVar': 33.15,
'sellPrice1': 13.45,
'sellPrice2': None,
'sellPrice3': None,
'sellPrice4': None,
'sellPrice5': None,
'sellQuantity1': 2399.0,
'sellQuantity2': None,
'sellQuantity3': None,
'sellQuantity4': None,
'sellQuantity5': None,
'series': 'EQ',
'surv_indicator': None,
'symbol': 'DISHTV',
'totalBuyQuantity': None,
'totalSellQuantity': 2399.0,
'totalTradedValue': 692.76,
'totalTradedVolume': 5169827.0,
'varMargin': 33.15}
只获取lastPrice的值:
print(data['lastPrice'])
>>> 13.5