Correct XPath query to fetch div inner text

19,527

Use the text() function:

//div[@class='h1']/text()

Tested in phpFiddle

Share:
19,527

Related videos on Youtube

Wikki
Author by

Wikki

Updated on June 21, 2022

Comments

  • Wikki
    Wikki about 2 years

    I am using XPath to query into HTML document where there is following div has text:

    <div class="h1">2008 Honda Accord Coupe<small> — Wuse II</small></div>
    

    I wanted to fetch only the inner text of the <div class="h1">2008 Honda Accord Coupe and not include the <small>inner text</small>

    I am making following XPath query: //div[@class='h1'] which is definitely returning entire <div>...</div> node.

    How can I only fetch portion without <small>...</small>

    thanks