开发者

get hidden input value from page using curl

开发者 https://www.devze.com 2023-04-01 20:46 出处:网络
I am using curl to display a page response on a thank you page.The code looks something like this: $curl_handle=curl_init();

I am using curl to display a page response on a thank you page. The code looks something like this:

$curl_handle=curl_init(); curl_setopt($curl_handle,CURLOPT_URL,'http://www.site.com'); curl_exec($curl_handle开发者_Python百科); curl_close($curl_handle);

The page above 'www.site.com' has a hidden input value in it that looks something like this:

<input type="hidden" id="my_id" value="123" />

All i need to do is grab the value ('123') from this hidden input and echo it out on my page.

Would be grateful if anyone could help me out with this.

Thanks!


You may use DOMDocument to parse HTML and get the value from the input element. I've not test this code, but quick code should look something like this:

$doc = new DOMDocument();
$doc->loadHTMLFile('http://www.site.com');
$id = $doc->getElementById('my_id')->getAttribute('value');

For example, cnn.com has the following html code on the front page.

<a id="nav-us" href="/US/" title="U.S. News Headlines Stories and Video from CNN.com">U.S.</a>

The following code would echo "U.S. News Headlines Stories and Video from CNN.com"

$doc = new DOMDocument();
$doc->loadHTMLFile('http://www.cnn.com');
$title = $doc->getElementById('nav-us')->getAttribute('title');
echo $title;
0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号