function getLinksForUrlDOM($url, $useProxy = true) { $linksCount = 0; $linksCountIndex = 0; $linkCountIn = 0; $linkCountOut = 0; $linkCountOur = 0; $params = array(); if ($useProxy) { $proxyService = new ProxiesService(); $res = $proxyService->getRandomProxyData(); if (PEAR::isError($res)) { return $res; } $params["proxyData"] = $res; } $pageContent = UrlUtils::loadPage($url, $params); if (strlen(trim($pageContent)) == 0) { return new PEAR_Error("Empty content"); } $dom = html_doc($pageContent); if (!$dom) { return new PEAR_Error("Can't create DOM"); } $currUrl = parse_url($url); $aTags = $dom->get_elements_by_tagname("a"); foreach ($aTags as $a) { if (!$a->has_attribute("href")) { continue; } $url = $a->get_attribute("href"); if (strlen(trim($url)) == 0) { continue; } $u = parse_url($url); if (!isset($u["host"])) { $linkCountIn++; } else { if (strcmp(removeWWW($u["host"]), removeWWW($currUrl["host"])) == 0) { $linkCountIn++; } else { if (strpos(removeWWW($u["host"]), "." . removeWWW($currUrl["host"])) !== false) { $linkCountOur++; } else { $linkCountOut++; } } } $linksCount++; } // Подсчет в noindex $noIndexTags = $dom->get_elements_by_tagname("noindex"); foreach ($noIndexTags as $noIndex) { $aTags = $noIndex->get_elements_by_tagname("a"); foreach ($aTags as $a) { if (!$a->has_attribute("href")) { continue; } $url = $a->get_attribute("href"); if (strlen(trim($url)) == 0) { continue; } $linksCountIndex++; } } return array($linksCount, $linksCountIndex, $linkCountIn, $linkCountOut, $linkCountOur); }
function html_doc_file($filename) { return html_doc($filename, true); }
/** * Инициализирует массив ссылок на страницы результата запроса * Для других поисковиков переопределяется * @return boolean */ function initPagesLinks() { $match = array(); $pattern = "/<div\\s+class=n>(.+?)<\\/div>/si"; if (!preg_match($pattern, $this->pageContent, $match)) { return false; } $html = @html_doc($match[1]); $links = $html->get_elements_by_tagname("a"); for ($i = 0; $i < sizeof($links); $i++) { $this->pagesLinks[] = $links[$i]->get_attribute("href"); } // Сохранить урл последней ссылки if (sizeof($links) > 0) { $this->lastPageUrl = $this->pagesLinks[sizeof($links) - 1]; } return true; }