【发布时间】:2020-08-08 20:32:50
【问题描述】:
我想从下面的网页中读取 NIFTY 50 的“打开”、“高”和“关闭”值。 https://www1.nseindia.com/live_market/dynaContent/live_watch/live_index_watch.htm
下面的代码以前可以工作。看起来网页有一些变化,我无法读取这些值,因为我遇到了错误。
nifty_50_row = table.find_all('tr')[2] # get first row of prices
AttributeError: 'NoneType' object has no attribute 'find_all'
需要您的帮助来解决此问题。
我的代码如下:
url ='https://www1.nseindia.com/live_market/dynaContent/live_watch/live_index_watch.htm'
options = webdriver.ChromeOptions()
options.add_argument('headless') # disable Chrome browser GUI interface
driver = webdriver.Chrome(r'/usr/bin/chromedriver', options=options)
driver.get(url)
soup = bs4.BeautifulSoup(driver.page_source, 'html.parser')
table = soup.find('table', id='liveIndexWatch')
nifty_50_row = table.find_all('tr')[2]
high_low = nifty_50_row.find_all('td')[3:7]
h=high_low[1].text
c=high_low[3].text
l=high_low[2].text))
todays_open =high_low[0].text
todays_high = high_low[1].text
todays_low = high_low[2].text
prev_day_close = high_low[3].text
【问题讨论】: