Python 如何在Beautiful Soup中找到特定的div文本

Python 如何在Beautiful Soup中找到特定的div文本,python,python-3.x,beautifulsoup,Python,Python 3.x,Beautifulsoup,我有以下html: from bs4 import BeautifulSoup as soup html_doc = """<div class="__cast-member" content="Vishal Krishna Reddy" itemprop="name"><div class="__cast-image wow fadeIn"><meta content="https://in.bmscdn.com/iedb/artist/images/websit

我有以下html:

from bs4 import BeautifulSoup as soup
html_doc = """<div class="__cast-member" content="Vishal Krishna Reddy" itemprop="name"><div class="__cast-image wow fadeIn"><meta content="https://in.bmscdn.com/iedb/artist/images/website/poster/large/vishal-krishna-reddy-16275-24-03-2017-15-17-54.jpg" itemprop="image"><img alt="Vishal Krishna Reddy" data-error="//in.bmscdn.com/webin/profile/user.jpg" data-lazy="//in.bmscdn.com/iedb/artist/images/website/poster/large/vishal-krishna-reddy-16275-24-03-2017-15-17-54.jpg" title="Vishal Krishna Reddy"/></meta></div><br/>Developer<br><span class="__role">Actor</span><br><span class="__characterName">As Kathiravan</span></br></br></div>"""
html = soup(html_doc, "html.parser")
Cast=html.find("div", {"class":"__cast-member"})
print Cast.text
从bs4导入BeautifulSoup作为汤
html_doc=“”
开发者
演员
作为Kathiravan html=soup(html_doc,“html.parser”) Cast=html.find(“div”,“class”:“\uu Cast-member”}) 打印Cast.text
输出:developeractoraskathiravan

但是我只需要输出:Developer

您可以使用该属性获取所需的文本。首先用
class=“\uu cast-image wow fadeIn”
找到
标签。所需的文本位于此标记之后。因此,在此标记上使用
.next_sibling
。但是首先你会得到

,所以再次使用它

>>> soup.find('div', class_='__cast-image').next_sibling
<br/>
>>> soup.find('div', class_='__cast-image').next_sibling.next_sibling
'Developer'
>>soup.find('div',class=''cast-image')。下一个兄弟姐妹

>>>soup.find('div',class=''cast-image')。下一个兄弟姐妹。下一个兄弟姐妹 “开发商”