首页 > 解决方案 > discory.py BeautifulSoup 在许多 div 类后面得到一个类

问题描述

我有以下html代码:

<div class="one">
   <div class="two">
      <div class="three">
         <a class="three" href="link">My link</a>
      </div>
   </div>
</div>

我怎样才能得到href链接?

标签: htmlbeautifulsoupdiscordbotsdiscord.py

解决方案


这将为您提供 html 页面中的所有链接。

soup = BeautifulSoup(html)

for a in soup.find_all('a', href=True):
    print(f"Found the URL:{a['href']}")

推荐阅读