Python discord.py BS4选择具有相同类名的第二个div
我有以下(简化的)html代码:Python discord.py BS4选择具有相同类名的第二个div,python,html,beautifulsoup,discord,discord.py,Python,Html,Beautifulsoup,Discord,Discord.py,我有以下(简化的)html代码: <div class="container"> *other html* </div> <div class="container"> *html i need* </div> *其他html* *我需要html* 如何获取第二个div的信息?使用BeautifulSoup的find_all()功能,您可以获得与您的条件相匹配的HTML元素列表。见: 因此,您可以通过调
<div class="container">
*other html*
</div>
<div class="container">
*html i need*
</div>
*其他html*
*我需要html*
如何获取第二个div的信息?使用BeautifulSoup的find_all()
功能,您可以获得与您的条件相匹配的HTML元素列表。见:
因此,您可以通过调用找到第二个元素:
soup.find_all('div', class_='container')[1]
使用BeautifulSoup的find_all()
函数,您可以获得一个HTML中符合条件的元素列表。见:
因此,您可以通过调用找到第二个元素:
soup.find_all('div', class_='container')[1]
soup.find_all('div',class='container')[1]
?@AndrejKesely我把它添加到了我的答案soup.find_all('div',class='container')[1]
?@AndrejKesely我把它添加到了我的答案中