2014-02-09 33 views
1

我有一些HTML,我用BeautifulSoup解析...麻烦了解如何使用findNextSiblings

<div class="book-page-sidebar"> 
    <h4>Production details</h4> 
    <dl class="product-details clearfix"> 
     <dt>Running Time:</dt> 
     <dd>1:20:25</dd> 

     <dt>Zip file size:</dt> 
     <dd>38.6MB</dd> 

     <dt>Catalog date:</dt> 
     <dd>2010-05-04</dd> 

     <dt>Read by:</dt> 
     <dd><a href="https://librivox.org/reader/204">Mark F. Smith</a></dd> 

     <dt>Book Coordinator:</dt> 
     <dd><a href="https://librivox.org/reader/204">Mark F. Smith</a></dd> 

     <dt>Meta Coordinator:</dt> 
     <dd><a href="https://librivox.org/reader/4009">Diana Majlinger</a></dd> 

     <dt>Proof Listener:</dt> 
     <dd><a href="https://librivox.org/reader/496">Ans Wink</a></dd>     
    </dl> 

</div> 

我想用文字Running Time: DT标签后抢在DD标签文本1:20:25。 所以,我想这段代码...

paraText = soup.find(text = re.compile ('Running Time:')) 
print paraText.findNextSiblings('dd') 

...但没有输出。我究竟做错了什么?

回答

2

find_next或findNext应该这样做。

paraText = soup.find(text = re.compile ('Running Time:')) 
print paraText.findNext('dd') 
+0

太棒了!谢谢你刚刚救了我几个小时,把我的头撞在墙上:) –

+0

Np,你应该检查所有美丽的汤lib提供的方法。简单的方法是简单地打印目录(汤)。干杯。 – adifire