贴下代码 大家可以跑下,就现有的逻辑可以优化吗?目前我只能手动每次 20,但是以后网站更新就太麻烦
$begin="
http://www.ygdy8.net/html/gndy/china/list_4_2.html";
$data=array();
$detail=array();
for ($i=70; $i <90; $i++) {
$url="
http://www.ygdy8.net/html/gndy/china/list_4_{$i}.html";
$str=file_get_contents($url);
if($str){
preg_match_all("/href=\"(.*?)\"/", $str,$urll);
foreach ($urll[1] as $key => $value) {
if (strpos($value, "gndy/dyzz/")) {
if(!in_array($value, $detail)){
$detail[]=$value;
}
}
}
}
}
print_r($detail);
$base="
http://www.ygdy8.net";
foreach ($detail as $key => $value) {
$strs=file_get_contents($base.$value);
if($strs&&preg_match("/(ftp.*?)\"/", $strs,$urlls)){
if(!in_array($urlls[1], $data)){
$data[]=$urlls[1];
}
}
}
print_r($data);
$has=file("data.txt");
foreach ($data as $key => $value) {
if(empty($has)||!in_array($value, $has)){
$value=iconv("gbk", "utf-8", $value);
file_put_contents("data.txt", $value.PHP_EOL,FILE_APPEND);
}
}