擅长:python、mysql、java
<p>如果您知道希望始终在<code><h2></code>标记之后使用前4个<code><p></code>标记,则可以使用以下示例:</p>
<pre><code>import requests
from bs4 import BeautifulSoup
url = "https://www.adobe.com/support/security/advisories/apsa11-04.html"
soup = BeautifulSoup(requests.get(url).content, "html.parser")
txt = "\n".join(
map(lambda x: x.get_text(strip=True, separator=" "), soup.select("h2 ~ p")[:4])
)
print(txt)
</code></pre>
<p>印刷品:</p>
<pre><code>Release date: December 6, 2011
Last updated: January 10, 2012
Vulnerability identifier: APSA11-04
CVE number: CVE-2011-2462
</code></pre>