maccen
maccen

Reputation: 155

get value of input field with xpath

I'm trying to get the value of a hidden form with xpath, there are several input fields

        $dom = new DOMDocument();
        @$dom->loadHTML($html);

        // grab all the page
        $x = new DOMXPath($dom);

        $nodes = $x->query('/html/body/div/div[4]/div[2]/input');

        foreach ($nodes as $node) {

            echo $name1  = $node->getValue;     

        }   

this is the HTML code:

<input type="hidden" value="1199" name="year">

Upvotes: 7

Views: 24197

Answers (3)

jens walter
jens walter

Reputation: 14049

use:

/html/body/div/div[4]/div[2]/input[@name='year']/@value

Upvotes: 7

Dimitre Novatchev
Dimitre Novatchev

Reputation: 243599

Use:

/html/body/div/div[4]/div[2]/input[@value=1199 and @name='year']

Upvotes: 2

Vincent
Vincent

Reputation: 4056

Simply put @value at the end of your query.

Upvotes: 13

Related Questions