PHP抓取网页上的所有链接

		$html = file_get_contents('http://www.php.cn');
        $dom = new DOMDocument();
        @$dom->loadHTML($html);
        // grab all the on the page
        $xpath = new DOMXPath($dom);
        $hrefs = $xpath->evaluate("/html/body//a");
        for ($i = 0; $i < $hrefs->length; $i++) {
            $href = $hrefs->item($i);
            $url = $href->getAttribute('href');
            echo $url.'<br />';
        }

猜你喜欢

转载自blog.csdn.net/qq_42805749/article/details/88573541
今日推荐