[問題] python 讀取網頁資料問題

作者: kiloxx (名器)   2016-03-28 23:13:58
大家好:D
python超級新手
想請問以下的code
import urllib.request
from bs4 import BeautifulSoup as bs
stock =
'http://www.twse.com.tw/ch/trading/exchange/STOCK_DAY/genpage/Report201603/201
603_F3_1_8_2330.php?STK_NO=2330&myear=2016&mmon=03#'
page = urllib.request.urlopen(stock)
soup=bs(page.read(),"html5lib")
table = soup.find('table',{'class':'board_trad'})
for tr in table.select('tr'):
print (tr.select('td')[0].text, tr.select('td')[-1].text)
我最後面用tr.select('td')[0].text 可以順利貼出日期
可是一用tr.select('td')[1].text 就說我 list index out of range
可是index用-1就可以貼出成交股數
沒道理阿~~~是哪裡有問題? 要怎樣改才可以把完整的表格貼出來?
感激!!

Links booklink

Contact Us: admin [ a t ] ucptt.com