我正在尝试使用下面的代码提取股票的LTP。它不返回任何值。请告诉下面代码中的错误:
from selenium import webdriver
from bs4 import BeautifulSoup
driver=webdriver.Chrome("C:\\Users\\hp\\Desktop\\New folder\\chromedriver.exe")
input_keyword=input("enter the stock name/symbol/keyword:")
url="https://www.nseindia.com/search?q="+input_keyword
driver.get(url)
content=driver.page_source
soup=BeautifulSoup(content,"html.parser")
details=soup.find_all("div",class_="searchWrp")
print("Choose from the followings:")
for data in details:
name=data.div.a.text.replace("\n","").replace(" ","")
print(name)
driver.close()
stock_name=input("enter the stock name from above:")
driver=webdriver.Chrome("C:\\Users\\hp\\Desktop\\New folder\\chromedriver.exe")
url_stock="https://www.nseindia.com/get-quotes/equity?symbol="+stock_name
driver.get(url_stock)
content_stock=driver.page_source
soup_stock=BeautifulSoup(content_stock,"html.parser")
details_stock=soup.find_all("div",attrs={"class":"blkbox-whitetxt"})
for price in details_stock:
LTP=price.find(span).text
print(LTP)
运行文件('C:/Users/hp/Desktop/sharemarket.py',wdir='C:/Users/hp/Desktop')
输入股票名称/符号/关键字:安讯士银行 从以下选项中选择: AXISBANK 奥班克 丹班克 HBANKETF 世界银行ETF CORPBANK DCBBANK HDFCBANK ICICIBANKP 雷班克 清算银行 列出UtiAssetManagementCompanyLimited UTIBankExchangeTradedFund(UTIBank)发行的基金 小型金融银行上市仪式 列出UtiAssetManagementCompanyLimited UTIBankExchangeTradedFund(UTIBank)发行的基金 NiftyBankF&;O BankingSector模块 清算银行利率竞争 清算银行商品竞争 国际投资银行业务 印度商业银行:阿贝金纳模式
从上面输入股票名称:AUBANK
最后一个价格(以及其他信息)是从外部URL加载的。您可以使用此示例来获得它:
印刷品:
相关问题 更多 >
编程相关推荐