【发布时间】:2018-09-24 12:06:54
【问题描述】:
我正在尝试获得Artist results 和Song results,但是我不确定如何获得我想要的这两个值。这就是我所拥有的:
albums = soup.find('div', attrs={'class':'panel-heading'}, text=re.compile('Artist results:'))
for i in albums.find_all('a'):
print (i)
我想从artist results 得到什么:asap rocky、asap mob、asap ferg
同样,我想从song results 获得的信息是:ASAP by T.I、ASAP by Eric Bellinger 等。
<div class="panel">
<div class="panel-heading"><b>Artist results:</b><br><small>[1-3 of 3 total <span class="text-lowercase">Artists</span> found]</small></div>
<table class="table table-condensed">
<tr><td class="text-left visitedlyr">
1. <a href="https://www.azlyrics.com/a/asaprocky.html" target="_blank"><b>Asap Rocky</b></a></td>
</tr>
<tr><td class="text-left visitedlyr">
2. <a href="https://www.azlyrics.com/a/asapmob.html" target="_blank"><b>Asap Mob</b></a></td>
</tr>
<tr><td class="text-left visitedlyr">
3. <a href="https://www.azlyrics.com/a/asapferg.html" target="_blank"><b>Asap Ferg</b></a></td>
</tr>
</table>
</div>
<div class="panel">
<div class="panel-heading"><b>Song results:</b><br><small>[1-5 of 454 total <span class="text-lowercase">Songs</span> found]</small></div>
<table class="table table-condensed">
<tr><td class="text-left visitedlyr">
1. <a href="https://www.azlyrics.com/lyrics/ti/asap.html" target="_blank"><b>ASAP</b></a> by <b>T.I.</b><br>
<small>[Intro] <strong>Asap</strong>, <strong>asap</strong>, <strong>asap</strong> <strong>Asap</strong>, <strong>asap</strong>, <strong>asap</strong> Ay, ay, ay, ay, ay, you niggaz better exit <strong>Asap</strong>, <strong>asap</strong>, <strong>asap</strong>, <strong>asap</strong> Ay-s, ay-p, ay-s, ay-p <strong>Asap</strong>, <strong>asap</strong>, <strong>asap</strong>, <strong>asap</strong> Ay-s, ay-p, ay-s, ay-p <strong>Asap</strong>, <strong>asap</strong>, <strong>asap</strong>, <strong>asap</strong> A-s-a-p, A-S-A-P [Verse 1] I'm on my grind, grand h...</small></td>
</tr>
<tr><td class="text-left visitedlyr">
2. <a href="https://www.azlyrics.com/lyrics/ericbellinger/asap.html" target="_blank"><b>ASAP</b></a> by <b>Eric Bellinger</b><br>
<small>ou say? Cause girl I need that <strong>asap</strong> [Hook] Girl I need that <strong>asap</strong>, <strong>asap</strong>, <strong>asap</strong>, I need Girl I need that <strong>asap</strong>, <strong>asap</strong>, <strong>asap</strong>, I need Girl I need that <strong>asap</strong>, <strong>asap</strong>, <strong>asap</strong>, baby I need Girl I'm tryina taste that, taste that, I need Girl I need that <strong>asap</strong>, <strong>asap</strong>, ...</small></td>
</tr>
【问题讨论】:
标签: python regex web-scraping beautifulsoup