У меня есть веб-страница для анализа, источник следующий:
<div class=WordSection1>
<p class=MsoTitle><a name="_nvfbzzqeywr7"></a><span lang=EN>Geometry</span></p>
<h2><a name="_99n9742wmg4y"></a><span lang=EN>Algebraic Geometry </span></h2>
<p class=MsoNormal><span lang=EN>It is a type of geometry which deals with
zeros of multivariate polynomial. It consists of linear and polynomial
algebraic equations used to solve the sets of zeros. The uses of this type <span
class=GramE>consists</span> of Cryptography, String theory, etc.</span></p>
<h2><a name="_64xtqrllvykm"></a><span lang=EN>Discrete Geometry</span></h2>
<p class=MsoNormal><span lang=EN>It is a type of Geometry, mainly concerned
with the relative position of simple geometric objects, such as points, lines,
Triangles, Circles, etc.</span></p>
<h2><a name="_mdul98ybu9wv"></a><span lang=EN>Differential Geometry</span></h2>
<p class=MsoNormal><span lang=EN>It uses techniques of algebra and calculus for
problem solving. The different problem involves general relativity in physics <span
class=SpellE><span class=GramE>etc</span></span><span class=GramE>,.</span></span></p>
</div>
Я хочу проанализировать данные внутри в виде списка и соответствующий тег в другом списке, чтобы я мог отобразить его позже в форма python словаря. Мне даже приходится игнорировать другие теги, такие как h1 и h3.
Ожидаемые результаты:
headers = ['Algebraic Geometry','Discrete Geometry','Differential Geometry']
content = ['It is a type of geometry which deals with
zeros of multivariate polynomial. It consists of linear and polynomial
algebraic equations used to solve the sets of zeros. The uses of this type consists of Cryptography, String theory, etc.','It is a type of Geometry, mainly concerned
with the relative position of simple geometric objects, such as points, lines,
Triangles, Circles, etc.','It uses techniques of algebra and calculus for
problem solving. The different problem involves general relativity in physics etc,.']
Я могу получить все заголовки. Но для получения
теги внутри заголовков, я не могу получить результаты. Вот что я попробовал:
content = []
# find the node with id of "WordSection1"
mark = soup.find_all(class_="WordSection1")
print(mark)
# walk through the siblings of the parent (H2) node
# until we reach the next H2 node
for elt in mark.parent.nextSiblingGenerator():
if elt.name == "h2":
break
if hasattr(elt, "text"):
content.append(elt.text)
Пожалуйста, помогите мне в этом.