WWW1.NSEINDIA.COM正在努力刷新记录。NSE India最近推出了一个新的网站,采用了更新的技术。在这个网站上,我无法得到脚本的最后价格
我尝试了下面的代码来提取这些值,但它导致了HTML标记
import requests
from bs4 import BeautifulSoup
stockcode = "DISHTV"
print(stockcode)
stock_url = 'https://www.nseindia.com/get-quotes/equity?symbol=' + stockcode
print(stock_url)
headers = {'user-agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/79.0.3945.117 Safari/537.36'}
response = requests.get(stock_url, headers=headers)
print(response)
soup = BeautifulSoup(response.text, 'lxml')
data_array = soup.find(id="quoteLtp")
type(data_array)
print(data_array)
输出
DISHTV
https://www.nseindia.com/get-quotes/equity?symbol=DISHTV
<Response [200]>
<span id="quoteLtp"></span>
它应该给出13.50的结果是最后一个价格,但是我得到了标签作为输出,我已经附上了HTML标签和值的屏幕截图
我希望有很多人会尝试并取得成功。我希望你能帮我检索信息
非常感谢
问候 雅娜
页面是用
javascript
动态加载的,但是requests
不支持它。 但是,您可以使用nsetools库用
pip install nsetools
安装它输出:
要仅获取
lastPrice
的值,请执行以下操作:即使使用nsetools,在新的nse网站上,您也会面临问题;如卡住等。请参阅github中nsetools的问题部分
更好的方法是在aliceblue或samco这样的经纪人那里开户,他们在那里有免费的API
相关问题 更多 >
编程相关推荐