获取远程页面上的所有链接
|
1
2
3
4
5
6
7
8
9
10
11
|
$html = file_get_contents('http://www.php100.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.'<br />';
} |
本文转自许琴 51CTO博客,原文链接:http://blog.51cto.com/xuqin/1349648,如需转载请自行联系原作者