Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/293.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
如何用php在google上查找关键字位置_Php_Position_Keyword - Fatal编程技术网

如何用php在google上查找关键字位置

如何用php在google上查找关键字位置,php,position,keyword,Php,Position,Keyword,如何使用PHP在Google上找到我的关键字位置 我尝试了以下URL: 但我无法获得任何html源代码 我该怎么做 也许您应该使用为此目的编写的类,例如,我使用我制作的脚本。 由于它依赖于谷歌可能更改的html,因此不可靠,但目前它的工作是: <?php // Include the phpQuery library // Download at http://code.google.com/p/phpquery/ include("phpQuery-onefi

如何使用PHP在Google上找到我的关键字位置

我尝试了以下URL:

但我无法获得任何html源代码


我该怎么做

也许您应该使用为此目的编写的类,例如,我使用我制作的脚本。 由于它依赖于谷歌可能更改的html,因此不可靠,但目前它的工作是:

<?php

    // Include the phpQuery library
    // Download at http://code.google.com/p/phpquery/
    include("phpQuery-onefile.php");

    $country = "en";
    $domain = "stackoverflow.com";
    $keywords = "php google keyword rank checker";
    $firstnresults = 50;

    $rank = 0;
    $urls = Array();
    $pages = ceil($firstnresults / 10);
    for($p = 0; $p < $pages; $p++){
        $start = $p * 10;
        $baseurl = "https://www.google.com/search?hl=".$country."&output=search&start=".$start."&q=".urlencode($keywords);
        $html = file_get_contents($baseurl);

        $doc = phpQuery::newDocument($html);

        foreach($doc['#ires cite'] as $node){
            $rank++;
            $url = $node->nodeValue;
            $urls[] = "[".$rank."] => ".$url;
            if(stripos($url, $domain) !== false){
                break(2);
            }
        }
    }

    print "Country: ".$country."\n";
    print "Domain: ".$domain."\n";
    print "Keywords: ".$keywords."\n";
    print "Rank: ".$rank."\n";
    print "First urls:\n";
    print implode("\n", $urls)."\n";

?>


谢谢你的回答,但我试过了,效果不好。我正在寻找书面类或etcFYI,这是一个书面类。我刚刚尝试过,它得到了500个内部服务器错误@AmalMurali抱歉,在写作时没有看到你的评论。我强烈建议,这可能是最好的工具,而且是免费的,它还有很多其他的东西可以用来监控你的网站。你能告诉我如何为一个域解析两个或三个关键字吗?把关键字做成一个数组并在上面循环:
$keywords=array(“php谷歌关键字排名检查器”,“为一个域解析两个或三个关键字”)
foreach($keywords作为$keyword){
for($p=0;$p<$pages;$p++){
$baseurl=”https://www.google.com/search?hl=“$country.”&output=search&start=“.$start.”&q=“.urlencode($keyword);
..
}
打印“域:”.$Domain.\n”
print“关键字:.$keyword.\n”
print“排名:.$Rank.\n”
我尝试了该代码,它成功了。我更改了参数并找到了我的排名。我刷新了页面,排名下降了!我再次尝试了原始代码,但它不再有效。在我看来,谷歌正在感知页面请求并采取行动。有任何评论吗?