代码抓取

这里来玩玩吧
代码都是抓取的!随意的看看,没准有意外的收获。参考代码如下:

...
$root = "https://github.com/";
$urls = [];
foreach ($dats as $dat) {
    $url_item = $root . $dat->children(0)->children(0)->find("a")[0]->href;
    $item_html = new simple_html_dom();
    $item_html->load_file($url_item);
    $T1 = $item_html->find(".repository-content");
    if ($T1 && is_array($T1) && count($T1) > 0) {
        $files = $T1[0]->find(".file-wrap");
        $sources = $files[0]->find(".js-navigation-item");
        foreach ($sources as $source) {
            $T2 = $source->find(".css-truncate-target");
            if ($T2 && is_array($T2) && count($T2) > 0) {
                $T3 = $T2[0]->find("a");
                if ($T3 && is_array($T3) && count($T3) > 0) {
                    $url = $T3[0]->href;
                    $url_arr = explode(".", $url);
                    if (count($url_arr) > 1) {
                        $urls[] = $root . $url;
                    }
                }
            }
        }
    } 

    $item_html->clear();
}
$html->clear();
// 随机选取
$url = $urls[array_rand($urls)];
$detail_html = new simple_html_dom();
$detail_html->load_file($url);
$T5 = $detail_html->find(".repository-content")[0];
if ($T5 && is_array($T5) && count($T5) > 0) {
    $detail_content = $T5->find(".file")[0]->find(".blob-wrapper")[0];
    echo $detail_content->innertext;
    $data = '';
    $data = $data . $detail_content->innertext;
    $detail_html->clear();
    file_put_contents("a" . rand() * (rand() % 99) . ".html", $data);
}
$detail_html->clear();