擅长:python、mysql、java
<p>只有<code><plaintext></code>元素包含文本:</p>
<pre><code>for pt in root.findall('.//plaintext'):
if pt.text:
print(pt.text)
</code></pre>
<p><code>.text</code>属性保存元素的文本。在</p>
<p>对于您的URL,将打印:</p>
^{pr2}$
<p>看起来<code><pod></code>标记也有有趣的标题:</p>
<pre><code>for pod in root.findall('.//pod'):
print(pod.attrib['title'])
for pt in pod.findall('.//plaintext'):
if pt.text:
print('-', pt.text)
</code></pre>
<p>然后打印:</p>
<pre><code>Input
- sqrt(2)
Decimal approximation
- 1.4142135623730950488016887242096980785696718753769480...
Number line
Continued fraction
- [1; 2^_]
Constant name
- Pythagoras's constant
All 2nd roots of 2
- sqrt(2)~~1.4142 (real, principal root)
- -sqrt(2)~~-1.4142 (real root)
Plot of all roots in the complex plane
</code></pre>