2011-08-22 73 views
0

我想從'課程負責人'從此網頁http://www.westminster.ac.uk/schools/computing/undergraduate/computer-networks/bsc-honours-computer-network-security檢索名稱。如何才能做到這一點?我試過XPath檢索節點內容

//div[starts-with(@id,'content_div')]/*[self::h3 or self::h4 and .='Course Leader' or 'Course Leaders']/following-sibling::p[1] 

但它返回了錯誤的數據..我需要在課程負責人之後選擇'nodeContent'。

+0

你是如何能夠在所有的檢索數據? W3C驗證器稱這不是有效的XML。 –

+0

對不起,我粘貼錯誤剪切,編輯操作。另外我使用hpple來解析html數據。 –

回答

0

試試這個XPath:

//div[starts-with(@id, 'content_div')] 
    /p[ 
     (preceding-sibling::*[1][self::h3] or preceding-sibling::*[1][self::h4]) 
      and (preceding-sibling::*[1] = 'Course Leader' 
       or preceding-sibling::*[1] = 'Course Leaders') 
    ]