Есть несколько вариантов для вас.
Вариант 1:
В одну сторону, которая разделена на '\ n', без пробелов,тогда у вас будет список каждого текстового элемента.Тогда в этом случае вам нужен только первый элемент.
import bs4
html = '''<h1>
<img src="CHN.jpg" alt="image">
Zhuzhou Wide-Ocean Motor
<a class="button" href="/en/top300">
See more information
</a>
</h1>'''
soup = bs4.BeautifulSoup(html, 'html.parser')
text = [ item.strip() for item in soup.text.split('\n') if item.strip() != ''][0]
print (text)
Вывод:
print (text)
Zhuzhou Wide-Ocean Motor
Опция 2:
Найдите этот тег <a>
и получите предыдущего брата:
html = '''<h1>
<img src="CHN.jpg" alt="image">
Zhuzhou Wide-Ocean Motor
<a class="button" href="/en/top300">
See more information
</a>
</h1>'''
soup = bs4.BeautifulSoup(html, 'html.parser')
text = soup.find('a').previousSibling.strip()
print (text)
Вывод:
print (text)
Zhuzhou Wide-Ocean Motor
Опция 3:
Вероятно, так я и поступлю.Найдите тег <img>
и получите следующего брата:
html = '''<h1>
<img src="CHN.jpg" alt="image">
Zhuzhou Wide-Ocean Motor
<a class="button" href="/en/top300">
See more information
</a>
</h1>'''
soup = bs4.BeautifulSoup(html, 'html.parser')
text = soup.find('img').nextSibling.strip()
print (text)
Вывод:
print (text)
Zhuzhou Wide-Ocean Motor