i'm having a code for simple php crawler that fetches all the html pages from websites upto depth 5 but if ,I run that for getting all the data contained in a div tag with its id like [container, main ,wrapper.etc] then it show unexpected result...heres the php code ::
<?php
$a=$_POST['t1'];
function crawl_page($url, $depth = 5)
{
static $seen = array();
if (isset($seen[$url]) || $depth === 0) {
return;
}
$seen[$url] = true;
$dom = new DOMDocument('1.0');
@$dom->loadHTMLFile($url);
$anchors = $dom->getElementsByTagName('div');
foreach ($anchors as $element) {
$href = $element->getAttribute('id');
//$href = $element->find('div[id=main]', 0)->plaintext;
if (0 !== strpos($href, 'main')) {
$host = "http://".parse_url($url,PHP_URL_USER);
$href = $host. '/' . ltrim($href, '/');
}
crawl_page($href, $depth - 1);
}
echo "New Page:<br /> ";
echo "URL:",$url,PHP_EOL,"<br />","CONTENT:",PHP_EOL,$dom->saveHTML(),PHP_EOL,PHP_EOL," <br /> <br />";
}
crawl_page($a, 5);
?>
this code is working good for anchor tags but i want this working for div tag only that fetches all the data contained in it nothing else. i want this for my project if anybody has done that then helpme out.......the html code is written down
<HTML>
<head>
<title></title>
</head>
<body>
<form method="POST" action="crawler1edit[2].php">
Enter Url:-<input type="text" name="t1">
<input type="submit" value="send" name="s1">
</form>
</body>
</HTML>
in action attribute crawler1edit[2].php is the php file containing php code written at the top