Simple PHP Spider to Fetch URL’s in a Link

By | December 9, 2011

Hey there friends, its been sometime since I last updated this blog. So, here i’m with a mini spider script that can help you fetch the URL’s in a given link.

In my apache home directory I created a folder called php and saved the following code as sam.php.

I accessed sam.php appended with “?link=linux.india365.org ” and it displayed me the list of links available in the link specified. Replace the text marked in red with another URL to see the links

http://localhost/php/sam.php?link=linux.india365.org

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
<?php

$seed = $_GET["link"];

$see = shell_exec("wget $seed -O sample.html");

$input = "sample.html";

$data = file_get_contents($input);

preg_match_all("/http:\/\/[^\"
<div id=":71"><wbr>\s']+/", $data, $links, PREG_SET_ORDER);echo "<table>";foreach ($links as $link) {echo "<tr><td>$link[0]</td></tr>\n"<wbr>;</wbr>

}

echo "</table>";

?>

If you like this article, then please consider sharing it. Sharing really inspires us to do things much better!!