另一个网站上的 Php 反向链接检查器

问题描述 投票:0回答:3

我正在尝试制作一个脚本来检查网页是否有指向我的页面的反向链接。我找到了这个脚本,但问题是即使存在反向链接,它也会返回错误消息“未找到反向链接”。有人能告诉我这个脚本有什么问题吗? 这是我正在使用的脚本:

    require('simple_html_dom.php');

function CheckReciprocal( $targetUrl, $checkLinkUrl, $checkNofollow = true )
{
    $html = file_get_html($targetUrl);
    if (empty($html))
    {
        //@ Could not load file
        return false;
    }


    $link = $html->find('a[href^='.$checkLinkUrl.']',0);
    if (empty($link))
    {
        //@ Link not found
        return false;
    }


    if ( $checkNofollow && $link->hasAttribute('rel') )
    {
        $attr = $link->getAttribute('rel');
        return (preg_match("/\bnofollow\b/is", $attr) ? false : true);
    }


    return true;
} 

$targetUrl = 'http://example.com/test.html';


$checkLinkUrl = 'http://mysite.com';


if ( CheckReciprocal($test, $checkLinkUrl) )
{
    echo 'Link found';
}
else { echo 'Link not found or marked as nofollow'; }

谢谢!

php simple-html-dom
3个回答
0
投票

我不知道 simple_html_dom.php 的 $html->find() 是如何工作的,因为从未使用过它,但似乎你的问题就在那里。我会相信优秀的 DOMDocument + 正则表达式。

刚刚编写了一个函数并对其进行了测试,只需在 $url 上使用普通域+任何你想要的内容,不用担心 http(s) 或 www 之类的东西:

function checkBackLink($link, $url, $checkNoFollow = true){
    $dom = new DOMDocument();
$dom->loadHTMLFile($link);

    foreach($dom->getElementsByTagName('a') as $item){
        if($checkNoFollow){
            if(preg_match('/nofollow/is', $item->getAttribute('rel'))) continue;
        }
        if($item->hasAttribute('href') === false) continue;
        if(preg_match("#^(https?\://)?(www\.)?$url.*#i", $item->getAttribute('href'))) return true;
    }
}

if(checkBacklink('the link', 'example.com')){
    echo "link found";
} else {
    echo "Link not found or marked as nofollow";
}

如果你不喜欢它,但仍然想使用 simple_html_dom,只需确保 find() 是如何工作的,因为如果它只匹配精确的值,可能会很麻烦。


0
投票

批量锚文本和Dofollow / Nofollow检查器

它允许您根据以下条件集体检查反向链接:

  • 锚文本状态(拉出所有关键字或直接链接)
  • Dofollow 和 nofollow 状态
  • HTTP 状态

用途:

  • 在“域”框中,输入反向链接链接到的域名:“example.com”。
  • 在“反向链接 URL(每行一个):”文本字段中,您可以批量粘贴反向链接。 (使用 HTTP 或 HTTPS)。
  • 检查将检查您点击的反向链接十个到十个。它将以百分比形式显示交易状态以及剩余的反向链接数量。

项目文件https://github.com/ercanatay/Backlink-Checker.git


© www.soinside.com 2019 - 2024. All rights reserved.