一个简单的抓链接spider

首先一个html表单form.html:

<form action="spider.php" method="post">
input your website you’d like to snatch:
<input type="text" name="website">
<input type="submit" value="Submit">
</form>

 

然后是spider.php:

<?php
if ($_POST["website"]) {
    $url = $_POST["website"];
} else {
    $url = ‘http://www.baidu.com’;
}
//echo $url;
$html = file_get_contents($url);
echo "Page : " . $url;
preg_match_all("/http://[^"s’]+/", $html, $matches, PREG_SET_ORDER);
foreach ($matches as $val) {
    echo "<li>|–" . $val[0] . "<br>";
}
?>