我的问题:直到 2018 年 3 月 31 日,我的函数 get_settldays() 返回了预期的日期值。此后 settlDays.contents 为空;但是在Mozilla浏览器中检查这个标签,有预期的内容
import sys, mechanicalsoup, re, datetime
def get_settldays(soup):
settlDays = soup.find('select', id="cmeTradeDate")
settlDays = re.findall('\d\d/\d\d/\d\d\d\d',str(settlDays.contents))
return [datetime.datetime.strptime(adat, '%m/%d/%Y') for adat in settlDays]
url = "http://www.cmegroup.com/trading/equity-index/us-index/e-mini-sandp500_quotes_settlements_futures.html"
browser = mechanicalsoup.StatefulBrowser()
try:
browser.open(url)
except:
print('Error:', str(sys.exc_info()[1]))
browser.close()
quit()
soup = browser.get_current_page()
settlDays = soup.find('select', id="cmeTradeDate")
print('\nsettlDays', settlDays) #remains empty??
print('\nsettlDays.content', settlDays.contents)
browser.session.close()
browser.close()
是否知道为什么 settlDays.contents 仍然为空?