Webスクレイピングで、、

インターンの方でWebスクレイピングが必要になったので、お勉強。

shop.oreilly.com

f:id:kimoppy126:20170702162842p:plain

 

このHTML中の

<tr class="gift" id="gift1"><td>
<tr class="gift" id="gift2"><td>
<tr class="gift" id="gift3"><td>
<tr class="gift" id="gift4"><td>
<tr class="gift" id="gift5"><td>
をとってきたいんだけど、

from urllib.request import urlopen
from bs4 import BeautifulSoup
html = urlopen("http://www.pythonscraping.com/pages/page3.html")
bsObj = BeautifulSoup(html, "html.parser")
for sibling in bsObj.find("table").tr.next_sibilings:
print(sibling)
でとってこれて、

from urllib.request import urlopen
from bs4 import BeautifulSoup
html = urlopen("http://www.pythonscraping.com/pages/page3.html")
bsObj = BeautifulSoup(html, "html.parser")
for sibling in bsObj.find("tbody").tr.next_sibilings:
print(sibling)

でとってこれないのがなんでかわからない。

AttributeError: 'NoneType' object has no attribute 'tr'
エラーから考えるとtbodyはタグとして認識されてない(?)ぽい