2014-02-09 32 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