简体   繁体   中英

xpath for extracting text from self and child node

here is my situation

i want to select " Buy 2 Hills Feline Maint Light 10kg and Save a further £4.00! " only from bellow html

Note: i am using XPath 1.0

<div>
    <a>
        <b>
            <u>Multi-Buy:</u>
        </b>
        <br/>
        Buy 
        <b>2</b>
         Hills Feline Maint Light 10kg and 
        <b>
            <font color="#CC0000">Save a further £4.00!</font>
        </b>
        <br/>
        <i>Simply add 2 to your basket.</i>
    </a>
</div>

here is my effort

//div/a/text()

by using this i am missing child node text

/div/a//text()

if i use this i am getting extra text

由于此HTML的结构不便于以任何干净的方式提取它,因此,我提出以下建议:

/div/a//text()[not(. = 'Multi-Buy:' or contains(., 'to your basket'))]

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM