Python 如何获得美丽的汤从href和类获得链接?

Python 如何获得美丽的汤从href和类获得链接?,python,html,download,beautifulsoup,Python,Html,Download,Beautifulsoup,我正在编写一个脚本,从一个网站下载多个flac,我正在使用Beauty Soup获取flac链接,并使用urlopen下载链接 我希望BS搜索以.flac结尾的链接(我不知道文件名,只是扩展名EX:1文件是XXX.flac,另一个是YYY.flac) flac文件的HTML在这里 <b><a class=location href="/soundtracks/index.php">Soundtracks</a><font class=location&g

我正在编写一个脚本,从一个网站下载多个flac,我正在使用Beauty Soup获取flac链接,并使用urlopen下载链接

我希望BS搜索以.flac结尾的链接(我不知道文件名,只是扩展名EX:1文件是
XXX.flac
,另一个是
YYY.flac

flac文件的HTML在这里

<b><a class=location href="/soundtracks/index.php">Soundtracks</a><font class=location> &raquo </font><a href="/soundtracks/highquality/index.php">High Quality Game 
Soundtracks [FLAC]</a><font class=location> &raquo </font><a href="/soundtracks/highquality/Metal_Gear_20th_Anniversary/72">Metal Gear 20th Anniversary</a><font class=location> &raquo 01 Metal Gear 20 Years History -Past, Present, Future- Download</font></b><h1>Metal Gear 20th Anniversary Download Links:</h1><a style="font-size: 16px; font-weight:bold;" href="http://50.7.161.234/bks/94/245/Music/[029] MG 20th Anniversary [FLAC]/01 Metal Gear 20 Years History -Past, Present, Future-.flac">Metal Gear 20th Anniversary - 01 Metal Gear 20 Years History -Past, Present, Future-</a> <font face="Verdana" style="font-size: 16px;">Format: FLAC, Size: 76M</font><br> <font face="Verdana" style="font-size: 10px;"><b>Note: If the file starts playing in your browser window, try right-clicking and "Save Target As"</b></font><br>

您的代码正在尝试匹配链接到这些FLAC的锚定标记中不存在的
id
属性

而是使用正则表达式来匹配以
.flac
结尾的
href

t = soup.find_all(href=re.compile(".flac$"))

我对靓汤很陌生,我不知道如何解决这个问题,我花了一个小时研究,但我找不到任何相关的东西。很抱歉。您意识到在您显示的html中没有带有
id=“flac”
的元素吗?正如我所说,我是个新手,如何让它搜索类“位置”?@Marcin的评论进一步,“如果为名为
id
的参数传入一个值,Beauty Soup将根据每个标记的
id
属性进行筛选:”()请参见:
t = soup.find_all(href=re.compile(".flac$"))