通过 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);
任何线索可能会发生什么?