XPath检索nodeContent

时间:2011-08-22 17:43:50

标签: html objective-c xml xpath html-parsing

我想从此网页http://www.westminster.ac.uk/schools/computing/undergraduate/computer-networks/bsc-honours-computer-network-security中的“课程负责人”中检索该名称。如何才能做到这一点?我试过了

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

但它返回错误的数据..我需要在课程负责人之后选择'nodeContent'。

1 个答案:

答案 0 :(得分: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')
     ]