<?php

$num = $_GET['num'];
if($num == null || $num == ''){
    $num = 0;
}

$do_array = file("list.txt");
//$domain = $do_array[$num];
//$length = sizeof($do_array);


foreach($do_array as $domain){
    
    
    $domain = trim($domain);
    
    $url = "https://m.sm.cn/s?q=site%3A{$domain}&from=smor&safe=1&by=submit&snum=0";
    
    $html = file_get_contents($url);
    
    preg_match('/<i>(.*)<\/i>个网页/s',$html,$match);
    $file = fopen($_SERVER['DOCUMENT_ROOT']."/domains_query_sm/shoulu.txt",'a');
    $str = $match[1];
    if($str == ''){
        $str = "没有收录";
    }
    $str = "{$domain}:{$str}\n";
    fwrite($file,$str);
    fclose($file);
    
    echo "{$str}<br>";
    
}
/*else{
    echo "<h1>程序运行完毕:收录信息如下</h1>";
    return;
    getshoulu();
    exit();
}*/
echo "<h1>程序运行完毕:收录信息如下</h1>";
getshoulu();
//采用跳转形式 避免数据过多程序崩溃
//$num=$num+1;
//echo "<script>window.location.href='http://104.227.29.146/domains_query_sm/sm.php?num={$num}';</script>";

function getshoulu(){
    //读取收录信息
    $file = file("shoulu.txt");
    unlink($_SERVER['DOCUMENT_ROOT']."/domains_query_sm/shoulu.txt");
    //一共收录
    $count_all = 0;
    
    foreach($file as $line){
        
        //切割数据
        if($line==''){
            continue;
        }
        $str = explode(":",$line);
        //当前域名
        $domain = $str[0];
        //收录数量
        $count = str_replace(",","",$str[1]);
        $count = trim($count);
        echo "<p>{$domain} => {$count}</p>";
        $count_all += $count;
        
    }
    echo "<div style='width: 100%;position:fixed;top:0;text-align:center;background:#6fd9dc7d'><h1 style='color:green'>总收录【{$count_all}】</h1>";
}
Last modification:May 26th, 2020 at 02:18 pm
如果觉得我的文章对你有用,请随意赞赏