PHP DOM
Posted: Wed Aug 22, 2007 2:34 am
The below code i posted fetches an html page and searches for the occurence of forms .. And if found the form values are printed
But i need to print also the input text variables associated with the form [they should be mutually dependent]
below is the code
Waiting for reply.
But i need to print also the input text variables associated with the form [they should be mutually dependent]
below is the code
Code: Select all
<?php
$target_url = "www.dnschart.com";
$ch = curl_init();
curl_setopt($ch, CURLOPT_USERAGENT, $userAgent);
curl_setopt($ch, CURLOPT_URL,$target_url);
curl_setopt($ch, CURLOPT_FAILONERROR, true);
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, true);
curl_setopt($ch, CURLOPT_AUTOREFERER, true);
curl_setopt($ch, CURLOPT_RETURNTRANSFER,true);
curl_setopt($ch, CURLOPT_TIMEOUT, 10);
$html= curl_exec($ch);
$dom = new DOMDocument();
@$dom->loadHTML($html);
$params = $dom->getElementsByTagName('form');
foreach ($params as $param) {
echo $param -> getAttribute('name').'<br>';
if($param->hasChildNodes())
{
echo "true";
echo "<br>";
$children = $param->childNodes;
echo $children->getElementsByTagName('input').'<br>';
foreach($children as $child)
{
echo $child->getAttribute('name');
}
}
else
{
echo "false";
echo "<br>";
}
?>