because select Method also returns Tag A collection of objects , So you can use Tag Object to get the node attribute value and text content . To get the property value, you can use attrs, It can also be used directly [...] Refers to the attributes of the node . To get the text content of the node, you can use get_text Method , You can also use string attribute .
The following example uses CSS The selector selects a specific a node , And get the a Node href Attribute value and text content .
from bs4 import BeautifulSoup
html = '''
<div>
<ul>
<li class="item1" value1="1234" value2 = "hello world">
<a href="https://geekori.com"> geekori.com</a>
</li>
<li class="item">
<a href="https://www.jd.com"> Jingdong Mall </a>
<a href="https://www.google.com"> Google </a>
</li>
</ul>
<ul>
<li class="item3"&g