У меня есть следующий HTML-код:экстракта имя класса из тега BeautifulSoup питона
<td class="image">
<a href="/target/tt0111161/" title="Target Text 1">
<img alt="target img" height="74" src="img src url" title="image title" width="54"/>
</a>
</td>
<td class="title">
<span class="wlb_wrapper" data-caller-name="search" data-size="small" data-tconst="tt0111161">
</span>
<a href="/target/tt0111161/">
Other Text
</a>
<span class="year_type">
(2013)
</span>
Я пытаюсь использовать красивый суп для разбора определенных элементов в табуляцией файл. я получил некоторую большую помощь и иметь:
for td in soup.select('td.title'):
span = td.select('span.wlb_wrapper')
if span:
print span[0].get('data-tconst') # To get `tt0082971`
Теперь я хочу, чтобы получить «Target Text 1».
Я пробовал некоторые вещи, как выше текста, такие как:
for td in soup.select('td.image'): #trying to select the <td class="image"> tag
img = td.select('a.title') #from inside td I now try to look inside the a tag that also has the word title
if img:
print img[2].get('title') #if it finds anything, then I want to return the text in class 'title'
вы сделали любую попытку извлекая сами – Blender
я редактировал пост выше – kegewe
другой нити здесь:.? Http: // StackOverflow .com/questions/41369344/beautifulsoup4-how-to-retrieve-a-list-of-the-class-name-of-specific-tag/41369459 # 41369459 – JinSnow