2011-12-12 287 views
4

我想在PHP中编程以获取我网站中的所有页面链接,因为我想检查我的网站的每个页面的pagerank,是否有工具或库或实现的算法在PHP中获取所有页面链接的特定网站?如何获取特定网站中的所有页面链接?

+1

这听起来像你在描述一个谷歌刮板。 –

+0

http://stackoverflow.com/questions/5919760/recognizing-http-links-and-creating-anchor-tags/5919821#5919821 – Teneff

+1

This http://stackoverflow.com/questions/361285/web-crawler-links- page-logic-in-php可能对你有用。 –

回答

6

你可以试试这个:

<?php 
    $original_file = file_get_contents("http://www.your_domain.com/page"); 
    $stripped_file = strip_tags($original_file, "<a>"); 
    preg_match_all("/<a(?:[^>]*)href=\"([^\"]*)\"(?:[^>]*)>(?:[^<]*)<\/a>/is", $stripped_file, $matches); 
?> 

$比赛[0]将包含完整的一个标签;例如:<a href="link">text</a>

$匹配[1]仅将包含在A标签的HREF;例如:link

我希望这会帮助你。 关心!

相关问题