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

2024-05-18 13:56:36 发布

您现在位置:Python中文网/ 问答频道 /正文

我正在编写一个脚本从一个网站下载多个flac,我使用beautifulsoup获取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>

我试图找到id.t = soup.find(id="flac"),但没有得到任何相关的结果。我对此一无所知,我不知道有什么办法可以解决它

如何让BS搜索并找到文件链接,然后将该文件链接分配给一个变量?在

^{pr2}$

Tags: 文件链接locationhistoryclassgearhreffont
1条回答
网友
1楼 · 发布于 2024-05-18 13:56:36

您的代码试图匹配链接到那些flac的锚标记中不存在的id属性。在

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

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

相关问题 更多 >

    热门问题