推 vi000246: body是None 所以取不到tbody 07/28 14:20
各位大大好
請問以下code:
from urllib.request import urlopen
from bs4 import BeautifulSoup
html_doc ='http://www.twse.com.tw/fund/BFI82U'
soup = BeautifulSoup(html_doc,'html.parser')
for i in soup.body.tbody.find_all('tr'):
print(i.td.get_text())
列印如下錯誤:
AttributeError Traceback (most recent call last)
<ipython-input-22-f987a99b5e34> in <module>()
4 soup = BeautifulSoup(html_doc,'html.parser')
----> 5 for i in soup.body.tbody.find_all('tr'):
6 print(i.td.get_text())
AttributeError: 'NoneType' object has no attribute 'tbody'
請問各位大大
為何會這樣呢
謝謝
--
※ 發信站: 批踢踢實業坊(ptt.cc), 來自: 123.192.84.222
※ 文章網址: https://www.ptt.cc/bbs/Python/M.1532758713.A.0B2.html