史努比在https上绊倒?

时间:2013-06-29 21:46:08

标签: php web-crawler snoopy

通过Snoopy运行一个简单的php网络爬虫 - http://turma.sourceforge.net/web/urlator/snoopy.html - 但是Fetchlinks()函数有点问题。通常,fetchlinks()会抓取页面上的所有链接并将它们很好地插入到数组中。这适用于所有http://链接,但任何https://链接都被添加到http://链接,并且不会放在数组中自己的插槽中。

损坏的https链接示例:

[472] => http://www.vapetropolis.ca/returns/https://www.vapetropolis.ca/product-warranties [473] => http://www.vapetropolis.ca/vaporizer-parts/davinci-vaporizer/https://www.vapetropolis.ca/product-warranties/https://www.vapetropolis.ca/customer/account/

正如您所看到的,他们已经被正确地形成了http://链接。

这是产生此

的代码
    function crawl_link($link, array &$sitewide_link_list) { 
        $snoopy = new Snoopy;
        //Get all links from first page
        $snoopy->fetchlinks($link);
        $currPage = $snoopy->results;

        //Add all links to global array
        //First, filter the links
            //Ensure all links are from correct domain

        $parsedDomain = 'www.vapetropolis.ca';

        if (is_array($currPage)) {

            foreach ($currPage as $link) {
                if ($parsedDomain == parse_url( $link, PHP_URL_HOST )) {                
                    if (!in_array($link, $sitewide_link_list)) {
                        array_push($sitewide_link_list, $link);
                    }   
                }

            }
        }
    }

    //Start crawl

    //Global array of links
    $sitewide_link_list = array();
    $checkList = array();
    $done = false;


    $domain = 'http://www.vapetropolis.ca';

    crawl_link($domain, $sitewide_link_list);



    print_r($sitewide_link_list);

有什么线索可能会发生什么?

0 个答案:

没有答案