2011-12-12 285 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

我希望這會幫助你。 關心!

相關問題