Get input field value using xpath

I am trying to get a hidden form value 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">
+5
source share
3 answers

Simply put @valueat the end of your request.

+8
source

using:

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

Using

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

All Articles