2016-12-12 7 views
0

ウェブサイトのサイトマップ内で提供されているすべてのURL、たとえばArgosを返そうとしています。これらのURLを取得したら、このプロセスを繰り返して結果のURLに含まれる可能性のあるURLを返す必要があります。サイトマップのURLを返す

http://www.argos.co.uk/sitemap.xmlリターン:

(ページが利用可能な複数のXMLのURLを含有していないに到達するまで、このプロセスが繰り返される)

http://www.argos. co.uk/product.xml 
http://www.argos. co.uk/product2.xml 
http://www.argos. co.uk/catalogue.xml 
http://www.argos. co.uk/buyers_guides.xml 
http://www.argos. co.uk/features_and_articles.xml 
http://www.argos. co.uk/static_pages.xml 
http://www.argos. co.uk/store_pages.xml 

http://www.argos.co.uk/product.xmlが、私は必要と独自のリンクが含まれていますたとえば、 現在まで:

var urls = require('sitemap-urls'); //package to return xml links from sitemap 
var cheerio = require('cheerio'); 
var request = require('request') 

// Returns all xml urls located within page source 
request('http://www.argos.co.uk/sitemap.xml', function (error, response, html) { 
    var sitemap = html; 
    var results = urls.extractUrls(sitemap); 

// If results returned, loop to make sitemap equal each url until array end 
    if(results) { 
    for(i = 0; i < results.length; i++) { 
     sitemap = results[i] 
     console.log(sitemap) 

    // Need to repeat url return process for each url returned 


    } 
    }                       
}); 

私は見落としている簡単な解決策があるかもしれません、どんな助けも高く評価されるでしょう、ありがとう。

答えて

2

は、私が何を探していることはクモ

<?php 
function crawl_page($url, $depth = 5) 
{ 
    static $seen = array(); 
    if (isset($seen[$url]) || $depth === 0) { 
     return; 
    } 

    $seen[$url] = true; 

    $dom = new DOMDocument('1.0'); 
    @$dom->loadHTMLFile($url); 

    $anchors = $dom->getElementsByTagName('a'); 
    foreach ($anchors as $element) { 
     $href = $element->getAttribute('href'); 
    if (0 !== strpos($href, 'http')) { 
      $path = '/' . ltrim($href, '/'); 
      if (extension_loaded('http')) { 
       $href = http_build_url($url, array('path' => $path)); 
      } else { 
       $parts = parse_url($url); 
       $href = $parts['scheme'] . '://'; 
       if (isset($parts['user']) && isset($parts['pass'])) { 
        $href .= $parts['user'] . ':' . $parts['pass'] . '@'; 
       } 
       $href .= $parts['host']; 
       if (isset($parts['port'])) { 
        $href .= ':' . $parts['port']; 
       } 
       $href .= $path; 
      } 
     } 
     crawl_page($href, $depth - 1); 
    } 
    echo "URL:",$url,PHP_EOL,"CONTENT:",PHP_EOL,$dom->saveHTML(),PHP_EOL,PHP_EOL; 
} 
crawl_page("http://hobodave.com", 2); 
+0

おかげだと思いますが、それはJavaScriptであることが必要です。これを明確にしないと申し訳ありません – Jordan

関連する問題