我正在尝试BeautifulSoup。我的要求是从网址获取数据并将其存储在文本文件中。首先,我正在测试信息包含的不同标签。我的程序是
from urllib.request import urlopen as uReq
from bs4 import BeautifulSoup
quote_page = 'http://www.bloomberg.com/quote/SPX:IND'
page = uReq(quote_page)
page_html = page.read()
page.close()
soup = BeautifulSoup(page_html, 'html.parser')
print(soup.find('div', attrs={'class':"price"}))
即使该课程中有信息,我也得到“无”输出。 HTML代码是
<div class="overviewRow__0956421f"><span class="priceText__1853e8a5">2,840.30</span><span class="currency__defc7184">USD</span></div>
我从website
处获得了参考