Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

get value of input field with xpath

Tags:

php

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">
like image 219
maccen Avatar asked May 01 '10 19:05

maccen


2 Answers

Simply put @value at the end of your query.

like image 77
Vincent Avatar answered Oct 11 '22 14:10

Vincent


use:

/html/body/div/div[4]/div[2]/input[@name='year']/@value
like image 40
jens walter Avatar answered Oct 11 '22 14:10

jens walter