How to find all links on any page in php_PHP Tutorial

WBOY
Release: 2016-07-13 17:18:00
Original
934 people have browsed it

Using DOM, you can easily grab links from any page. The code example is as follows:

Copy the code The code is as follows:

$html = file_get_contents('http://www.example.com');
$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.'
';
}

www.bkjia.comtruehttp: //www.bkjia.com/PHPjc/621705.htmlTechArticleUsing DOM, you can easily grab links from any page. The code example is as follows: Copy the code The code is as follows: $ html = file_get_contents('http://www.example.com'); $dom = new DOMDocum...
Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!