BeautifulSoup selector: select HTML elements containing multiple words
P粉878510551
2023-08-13 19:25:41
<p>Is there a way for me to use BeautifulSoup to get the text of a label that contains multiple words? </p>
<p>For example, if I have the following HTML: </p>
<pre class="brush:php;toolbar:false;"><div>
<div>
<a>hello there</a>
<a>hi</a>
</div>
<a>what's up</a>
<a>stackoverflow</a>
</div></pre>
<p>...I just want to get<code>hello there what's up</code></p>
You can definitely use BeautifulSoup to extract text from HTML tags that contain multiple words. In your example, you want to extract text from <a> tags that contain multi-word content. Here's how to achieve this using BeautifulSoup in Python.