<p>从锚标记获取<code>href</code>值</p>
<p>使用</p>
<ul>
<li>标签['hef']</li>
</ul>
<p>或</p>
<ul>
<li>tag.get('href')</li>
</ul>
<p>或</p>
<ul>
<li>tag.attrs.get('href')</li>
</ul>
<pre><code>from bs4 import BeautifulSoup
data='''<a href="https://dibbs2.bsm.dla.mil/Downloads/Awards/18SEP19/GS07F5933RSPEFA519F0433.PDF" target="DIBBSDocuments" title="Link To Delivery Order Document"><img alt="PDF Document" border="0" height="16" hspace="2" src="https://www.dibbs.bsm.dla.mil/app_themes/images/icons/IconPdf.gif" width="16"/></a>, <a href="https://dibbs2.bsm.dla.mil/Downloads/Awards/18SEP19/GS07F5933RSPEFA519F0433.PDF" target="DIBBSDocuments" title="Link To Delivery Order Document">SPEFA519F0433</a>'''
soup=BeautifulSoup(data,'html.parser')
for item in soup.select('a'):
print(item['href'])
print(item.get('href'))
print(item.attrs.get('href'))
</code></pre>
<hr/>
<p>若你们在寻找某个特定的锚定标记,那个么在findtaglike中添加更多的条件</p>
<pre><code>for item in soup.select('a[target="DIBBSDocuments"]'):
print(item['href'])
print(item.get('href'))
print(item.attrs.get('href'))
</code></pre>
<p>或者以href url开头</p>
<pre><code>for item in soup.select('a[href^="https://dibbs2.bsm.dla.mil/Downloads/Awards"]'):
print(item['href'])
print(item.get('href'))
print(item.attrs.get('href'))
</code></pre>