が、私はこのウェブサイトから、漢字の記述を抽出しようとしています、)(find_next_siblingからテキストを抽出:http://www.hsk.academy/en/hsk_1BeautifulSoup
例のHTML:
<tr>
<td>
<span class="hanzi"><a href="/en/characters/%E7%88%B1">爱</a></span>
<br/>ài</td>
<td>to love; affection; to be fond of; to like</td>
</tr>
を、私は最後のTDタグのテキストをしたいと思います文字の各説明のリストに入れる。しかし、現在、タグ自体を含めてタグ全体が与えられています。 .text find_next_sibling():AttributeError: 'NoneType'オブジェクトには属性 'text'がありません。
これは私のコードです:<span>
タグになります(id="flat_list"
を持つテーブル内の)クラスhanzi
のすべてのタグ
english_descriptions = []
table = soup.find('table', id='flat_list')
for e in table.select('.hanzi'):
english_desc = e.parent.find_next_sibling().text
if not any(english_desc in s for s in english_descriptions):
english_descriptions.append(english_desc)
この選択(発見):
for item in soup.find_all("td"):
EnglishItem = item.find_next_sibling()
if EnglishItem:
if not any(EnglishItem in s for s in EnglishDescriptionList):
EnglishDescriptionList.insert(count, EnglishItem)
count += 1
print EnglishDescriptionList
希望の出力のようにもっと明確にすることができます。 – Sandeep