lena berkova
Местный житель
- Регистрация
- 14 Янв 2009
- Сообщения
- 437
- Реакции
- 21
- Автор темы
- #1
нужно на странице найти заданную ссылку и проверить есть ли у ссылки атрибут nofollow-как сделать проверку?
Follow along with the video below to see how to install our site as a web app on your home screen.
Примечание: This feature may not be available in some browsers.
выдираешь все нужные ссылки и уже в них последовательно ищещь nofollow примерно такнужно на странице найти заданную ссылку и проверить есть ли у ссылки атрибут nofollow-как сделать проверку?
preg_match('/nofollow/',$links,$nofollow);
<?
class backlink
{
var $errors = '';
var $backlink = '';
var $backlink_parse = array();
var $backlink_path = '';
var $backlink_path_ar = array();
function backlink($backlink)
{
$this->backlink = $backlink;
$this->backlink_parse = parse_url($backlink);
$this->backlink_path = $this->backlink_parse['path'];
if ( substr($this->backlink_path,0,1)=='/' ) $this->backlink_path = substr($this->backlink_path,1);
if ( substr($this->backlink_path,-1)=='/' ) $this->backlink_path = substr($this->backlink_path,0,strlen($this->backlink_path)-1);
$backlink_path_ar = split("[/]",$this->backlink_path);
if ( count($backlink_path_ar)>0 )
{
foreach ( $backlink_path_ar as $k=>$v )
{
$v = trim($v);
if ( empty($v) ) unset($backlink_path_ar[$k]);
}
}
if ( count($backlink_path_ar)>0 ) $this->backlink_path_ar = $backlink_path_ar;
}
function subpath_check($rule)
{
if ( count($this->backlink_path_ar)>0 )
{
$path = '';
foreach ( $this->backlink_path_ar as $k=>$v )
{
$path.= empty($path) ? $v : "\/".$v;
if ( preg_match('/Disallow:\s*[\/]?'.$path.'[\/\*]?\s*$/i',$rule) ) return true;
}
}
return false;
}
function check($url)
{
$parse_url = parse_url($url);
/* robotos.txt */
$robots_url = 'http://'.$this->backlink_parse['host'].'/robots.txt';
$robots_data_ar = @file($robots_url);
if ( $robots_data_ar!==false )
{
if ( count($robots_data_ar)>0 )
{
foreach ( $robots_data_ar as $k=>$v )
{
$v = trim($v);
if ( !empty($v) )
{
if ( preg_match('/Disallow:\s*\/\s*$/i',$v) ) // запрет индексации всего
{
$this->errors = 'В '.$robots_url.' есть правило запрещающее индексировать.';
return false;
}
if (
preg_match('/Disallow:\s*[\/]?'.str_replace("/","\/",$this->backlink_path).'[\/\$]\s*$/i',$v) || // запрет индексации страницы
$this->subpath_check($v) // запрет индексации пути к странице
) {
$this->errors = 'В '.$robots_url.' есть правило запрещающее индексировать страницу '.$this->backlink;
return false;
}
}
}
}
}
/* META */
$meta = @get_meta_tags($this->backlink);
if (
eregi('noindex',$meta['robots']) ||
eregi('nofollow',$meta['robots'])
) {
$this->errors = 'На странице '.$this->backlink.' есть META данные запрещающие её индексацию.';
return false;
}
/* Link */
$data = '';
$fp = @fopen($this->backlink,"r");
if ( $fp )
{
while (!feof($fp)) $data.= fgets ($fp,4096);
fclose ($fp);
$pattern = array (
"'<script[^>]*?>.*?</script>'si", // Вырезается javascript
"'<noscript[^>]*?>.*?</noscript>'si", // noscript
"'<noindex[^>]*?>.*?</noindex>'si", // noindex
"'<a[^>]*?rel=[\"\']nofollow[\"\'].*?>'si", //nofollow
"'<\!--.*?-->'si", // remarka
);
$replace = array(" "," "," "," "," ");
$data = preg_replace($pattern, $replace, $data);
if ( preg_match_all('/<a.*?href=["\']http:\/\/(.*?)["\']/i', $data, $m) ) {
if ( count($m[1])>0 )
{
foreach ( $m[1] as $k=>$v ) if ( eregi($parse_url['host'],$v) ) return true;
}
}
$this->errors = 'На странице '.$this->backlink.' ссылка '.$url.' не найдена или не доступна к индексации.';
}
else $this->errors = 'Не удаётся открыть страницу '.$this->backlink;
return false;
}
}
/*
include 'backlink.php';
$bl = new backlink('Где ищем');
if ( !$bl->check('Что ищем') ) echo $bl->errors;
else echo 'OK!';
*/
?>