HTMLの一部は次のとおりです。
<td class="team-name">
<div class="goat_australia"></div>
<a href="http://www.waaaaa.com.au/g-smith/australia/melbourne">Melbourne</a><br />
Today
</td>
<td class="team-name">
<div class="goat_australia"></div>
<a href="http://www.waaaaa.com.au/g-smith/australia/sydney">Sydney</a><br />
Tomorrow
</td>
したがって、クラス名が「team-name」で、テキスト「Today」が含まれている場合にのみ、これらすべてのtdタグを返したいと思います。
これまでの私のコード:
from BeautifulSoup import BeautifulSoup
import urllib2, re
starting_url = urllib2.urlopen('http://www.mysite.com.au/').read()
soup = BeautifulSoup(''.join(starting_url))
soup2 = soup.findAll("td", {'class':'team-name'})
for entry in soup2:
if "Today" in soup2:
print entry
これを実行しても何も返されません。
私がその最後のifステートメントを取り出してただ置くなら
print soup2
すべてのtdタグを取り戻しますが、「今日」のタグと「明日」のタグなどがあります。
それで、何かポインタはありますか?soup.findAll関数に2つの属性を追加する方法はありますか?
また、findAllでfindAllを実行しようとしましたが、機能しませんでした。