Ich habe ein Problem, wo supple.find_all für ein bestimmtes Tag h2 erfolgreich ist, aber supp.find, das den Text angibt, schlägt fehl.Beautifulsoup-Tag - find_all erfolgreich, aber nicht erfolgreich gefunden
Ich muss die h2-Tags mit verschiedenen Text wie Einführung, Ergebnisse usw. wie im beigefügten Bild gezeigt finden.
Kann jemand bitte beraten? Vielen Dank.
print(soup.find_all('h2'))
[<h2 class="Heading">Abstract</h2>,
<h2 class="Heading" data-role="collapsible-handle" tabindex="-1">Introduction<span class="section-icon"></span></h2>,
<h2 class="Heading" data-role="collapsible-handle" tabindex="-1">Patients and methods<span class="section-icon"></span></h2>,
<h2 class="Heading" data-role="collapsible-handle" tabindex="-1">Results<span class="section-icon"></span></h2>,
<h2 class="Heading" data-role="collapsible-handle" tabindex="-1">Discussion<span class="section-icon"></span></h2>,
<h2 class="Heading" data-role="collapsible-handle" id="copyrightInformation" tabindex="-1">Copyright information<span class="section-icon"></span></h2>,
<h2 class="Heading" data-role="collapsible-handle" id="aboutarticle" tabindex="-1">About this article<span class="section-icon"></span></h2>,
<h2 class="u-isVisuallyHidden">Article actions</h2>, <h2 class="u-h4 u-jsIsVisuallyHidden">Article contents</h2>,
<h2 class="u-isVisuallyHidden">Cookies</h2>]
print(soup.find('h2', text='Introduction'))
None
Bitte zeigen Sie das HTML-Dokument, das Sie als Eingabe verwenden. Vielen Dank! Weitere Hilfe: http://stackoverflow.com/help/mcve. –