2013-04-22 46 views
0

我正在使用Hpple來傳遞HTML文件。該HTML文件與以下內容非常相似。使用Hpple解析HTML

<div class="entry"> 
     <p>some text here 
     <a>Inside a</a> 
     another text here 
     </p> 
     <div class="caption"> 
     caption here 
     </div> 
     <p>Blah 
     </p> 
    </div> 

我想看到的結果是「這裏有些文字在這裏另一個文本等等」(這忽略一切是標題股利和包括內部和之後的事情)

這裏有一些我」的查詢已經試過:

  1. "//div[@class='entry']/p" 結果:"some text here"
  2. "//div[@class='entry']//p" 結果:"some text here caption here Blah"
  3. "//div[@class='entry']/p//text()" 結果:Nothing

感謝。

回答

0

您可能自己回答了這個問題,但我剛剛有類似的問題。爲了讓我用

// DIV [@類=「入口」]文本//一個[@inside] // *

這讓我在裏面,你在呼喚什麼裏面的文字。讓我知道這個是否奏效。我自己仍然在學習解析HTML。祝你好運。

+0

實際上,我發現了問題。代碼實際上是正確的,我使用「// div [@ class ='entry']/p」。但我無法從TFHppleElemnt中提取正確的內容。 – 2013-04-25 22:14:49

+0

很高興你能工作! – Douglas 2013-04-25 22:42:43

+0

感謝您的幫助,雖然 – 2013-04-26 21:35:49

0

試試這個:

//div[@class='entry']//p//text() - should return "Some text here another text here Blah" 
//div[@class='entry']//text() - should return "Some text here another text here caption here Blah"