无法理解如何使用findNextSiblings

时间:2014-02-09 04:55:52

标签: python beautifulsoup

我有一些我用BeautifulSoup解析的HTML ...

<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>

我想在带有文字1:20:25的dt标签后抓取dd标签中的文字Running Time:。 所以我尝试了这段代码......

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

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

1 个答案:

答案 0 :(得分:2)

find_next或findNext应该可以解决问题。

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