Home Backend Development PHP Tutorial PHP keyword Baidu ranking batch check_PHP tutorial

PHP keyword Baidu ranking batch check_PHP tutorial

Jul 20, 2016 am 11:09 AM
doctype dtd html php public w3c xhtml Keywords batch Ranking check Baidu






关键字百度排名批量查





function tongji()
{
 $myhost = $_server['http_host'];
 if (preg_match("/(www.)?baiek.com/i", $myhost, $myout))
 {
  echo '';
 }
}

function libxml_display_error($error)
{
 $return = "
n";
 switch ($error->level)
 {
  case libxml_err_warning:
   $return .= "warning $error->code: ";
   break;
  case libxml_err_error:
   $return .= "error $error->code: ";
   break;
  case libxml_err_fatal:
   $return .= "fatal error $error->code: ";
   break;
 }
 $return .= trim($error->message);
 if ($error->file)
 {
  $return .= " in $error->file";
 }
 $return .= " on line $error->linen";
 return $return;
}

function libxml_display_errors()
{
 $errors = libxml_get_errors();
 foreach ($errors as $error)
 {
  print libxml_display_error($error);
 }
 libxml_clear_errors();
}

$kfname = '';
if (isset($_get['kf']))
{
 $kfname = trim($_get['kf']);
}
$version = '';
echo <<< eoth

eoth;
if (!file_exists($kfname) || !is_readable($kfname))
{
tongji();
exit('Please enter the correct Keyword list file (xml format, please refer to the readme file)! ');
}
libxml_use_internal_errors(true);
$doc = new domdocument();
$doc->load($kfname);
if (!$doc->schemavalidate('kw.xsd') )
{
print 'Error found in keyword list xml file! ';
libxml_display_errors();
tongji();
exit;
}

//Extract the keyword list and corresponding domain name from the xml file
$kwlist = array(); $g = 1;
$kgroups tutorial = $doc->getelementsbytagname("kgroup");
foreach ($kgroups as $kgroup)
{
$kwlist[$g]['domain'] = trim($kgroup->getelementsbytagname("kdomain")->item(0)->nodevalue);
$kwords = $kgroup-> getelementsbytagname("kword");
$w = 1;
foreach ($kwords as $kword)
{
if ($kword->haschildnodes())
{
$kwlist[$g]['kword'][$w] = trim($kword->firstchild->nodevalue);
}
$w++;
}
$g++ ;
}
?>


function get_dm_weight($h, $i)
{
//$h represents the url of the search results, $i represents the result ranking
$p = ceil($i / 10); //What page of the search results

$i_weight = array(1 => ; 52, 2 => 15, 3 => 10, 4 => 5, 5 => 5, 6 => 4, 7 => 1, 8 => 3, 9 => 2 , 0 => 3);
$h_str = preg_replace("/^.*?://(.*?)(#.*)?$/i", "$1$3", $h); //Remove the protocol (such as http) and #information fragment part in the url
$h_arr = explode("?", $h_str, 2);
$h0_arr = explode("/", $h_arr[0 ]);
if ($h0_arr[count($h0_arr) - 1] == '')
{
$level_l = count($h0_arr) - 1;
}
else
{
$level_l = count($h0_arr);
}
if (isset($h_arr[1]))
{
if ($h_arr[1] != '')
{
$level_r = count(explode("&", $h_arr[1]));
}
else
{
$level_r = 0;
}
}
else
{
$level_r = 0;
}
$dw = $i_weight[$i % 10] * pow(0.5, ($level_l + $level_r - 1)) * 9 / pow(10, $p);
return number_format($dw, 1);;
}

function fetch_baidu($d, $k)
{
 $urlw = urlencode(iconv("utf-8","gbk//ignore",$k));
 $max_srh_page = 2; //百度搜索结果50条/页,提取2页,也就是只在前100条搜索结果中检查排名,最大值可以设为16
 $baidu_ids = array(); //存储百度系列子站点占据的排名位置
 $baidu_mus = array(); //存储百度开放平台等优质站点占据的排名位置
 $isrank = 0; //$isrank = 1 当前域名下这个关键词获得排名; $isrank = 0 当前域名下这个关键词没有排名
 $all_count = 0; //测试变量,以确认匹配规则不会遗漏任何一条搜索结果
 $dm_weight = 0; //分析搜索结果页面中顶级、次级、目录、内页的情况,粗略反映一个关键字的竞争激烈程度,非常不准,仅供参考
 for ($page_no = 1; $page_no <= $max_srh_page; $page_no++)
{
if ($page_no > 16) break;
  $fail_try = 1;
  $pn = ($page_no - 1) * 50;
  $url = "http://www.baidu.com/s?wd={$urlw}&pn={$pn}&rn=50";
  $snoopy = new snoopy;
//  $snoopy->proxy_host = "127.0.0.1"; //采集可选代理ip,以免频繁抓百度反被百度咬
//  $snoopy->proxy_port = "80";   //proxy代理所用端口
  $snoopy->fetch($url);
  $contents = iconv("gbk","utf-8//ignore",$snoopy->results);
  unset($snoopy);
//  echo $contents;
  if (!preg_match("/此内容系百度根据您的指令自动搜索的结果/i",$contents,$out))
  {
   if ($fail_try > 5)
   {
    continue;
   }
   else
   {
    $fail_try++;
    $page_no--;
    sleep(30);
    continue;
   }
  }
  if (!isset($ebaidu))
  {
   $ebaidu = array('lt' => 0, 'lb' => 0, 'r' => 0); //记录百度推广数量,分为左上、左下、右侧
   if (preg_match_all("/ {
$ebaidu['lt'] = count($out_lt[0]);
}
if (preg_match_all("/

/i", $contents, $out_lt))
   {
    $ebaidu['lt'] = count($out_lt[0]);
   }
   if (preg_match_all("/
/i", $contents, $out_lb))
   {
    $ebaidu['lb'] = count($out_lb[0]);
   }
   if (preg_match_all("/
)|(
))[s|s]*?(((.*?))|(
))/i", $contents, $out_mu))
  {
   foreach ($out_mu[0] as $om_key => $om_val)
   {
    $om_id1 = $out_mu[3][$om_key];
    $om_href1 = $out_mu[4][$om_key];
    $om_id2 = $out_mu[6][$om_key];
    $om_href2 = $out_mu[7][$om_key];
    $om_title = strip_tags($out_mu[10][$om_key]);
    $baidu_mus[] = $om_id1 . $om_id2;
    $dm_weight = $dm_weight + get_dm_weight($om_href1 . $om_href2, $om_id1 . $om_id2);
    if (preg_match("/://(w*?.)*?baidu.com//i", $om_href1 . $om_href2, $om_domain))
    {
     $baidu_ids[] = $om_id1 . $om_id2;
    }
    if (preg_match("/://(w*?.)*?{$d}//i", $om_href1 . $om_href2, $om_domain))
    {
     echo '
' . $k . '' . $om_id1 . $om_id2 . '' . $om_title . '';
     $isrank = 1;
    }
   }
  }
  if (preg_match_all("/

()?(.*?)

.*?.*? ((d{4}-d{1,2}-d{1,2})|(d+小时前)|(d+分钟前)) .*?.*?
/i", $contents, $out_all))
  {
   foreach ($out_all[0] as $o_key => $o_val)
   {
    $o_id = $out_all[1][$o_key];
    $o_href = $out_all[3][$o_key];
    $o_title = strip_tags($out_all[4][$o_key]);
    $o_cache = $out_all[6][$o_key] . $out_all[7][$o_key] . $out_all[8][$o_key];
    $dm_weight = $dm_weight + get_dm_weight($o_href, $o_id);
    if (preg_match("/://(w*?.)*?baidu.com//i", $o_href, $o_domain))
    {
     $baidu_ids[] = $o_id;
    }
    if (preg_match("/://(w*?.)*?{$d}//i", $o_href, $o_domain))
    {
     echo '
' . $k . '' . $o_id . '' . $dm_weight . '%' . $o_title . '' . $o_cache . '';
     $isrank = 1;
    }
   }
  }
  //$all_count用来检查上述正则匹配是否匹配到所有搜索结果,特别关注百度系列站点、百度开放平台以及百度应用等有别于普通搜索结果
  if (isset($out_mu[0])) $all_count = $all_count + count($out_mu[0]);
  if (isset($out_all[0])) $all_count = $all_count + count($out_all[0]);
//  echo '
总共找到' . $all_count . '个匹配
';
  if (!preg_match("/  {
   break;
  }
 }
 if (count($baidu_mus) >= 1)
 {
  $bmus = implode(",", $baidu_mus);
 }
 else
 {
  $bmus = '';
 }
 if (count($baidu_ids) >= 1)
 {
  $bids = implode(",", $baidu_ids);
 }
 else
 {
  $bids = '';
 }
 if ($isrank == 1)
 {
  echo '上' . $ebaidu['lt'] . '下' . $ebaidu['lb'] . '右' . $ebaidu['r'] . '' . $bids . '' . $bmus . '';
 }
 else
 {
  echo '
' . $k . '0' . $dm_weight . '%上' . $ebaidu['lt'] . '下' . $ebaidu['lb'] . '右' . $ebaidu['r'] . '' . $bids . '' . $bmus . '';
 }
 unset($ebaidu);
}
//逐个域名与关键字采集百度排名信息并显示
set_include_path(".");
include "snoopy.class.php";
set_time_limit(0);
ob_flush(); flush(); ob_end_clean(); ob_implicit_flush(1);
echo '
';
echo '关键字排名竞争度网页标题百度快照百度推广数量百度占位百度mu占位';
foreach ($kwlist as $d_ks)
{
 $dm = $d_ks['domain'];
 echo '
域名:' . $dm . '';
 foreach ($d_ks['kword'] as $k)
 {
  fetch_baidu($dm, $k);
 }
}
echo '
';
?>


tongji();
?>


www.bkjia.comtruehttp://www.bkjia.com/PHPjc/444787.htmlTechArticle!doctype html public -//w3c//dtd xhtml 1.0 transitional//en http://www.w3.org/tr/xhtml1/dtd/xhtml1-transitional.dtd html xmlns=http://www.w3.org/1999/xhtml head meta http-equiv=con...
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn

Hot AI Tools

Undresser.AI Undress

Undresser.AI Undress

AI-powered app for creating realistic nude photos

AI Clothes Remover

AI Clothes Remover

Online AI tool for removing clothes from photos.

Undress AI Tool

Undress AI Tool

Undress images for free

Clothoff.io

Clothoff.io

AI clothes remover

Video Face Swap

Video Face Swap

Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Tools

Notepad++7.3.1

Notepad++7.3.1

Easy-to-use and free code editor

SublimeText3 Chinese version

SublimeText3 Chinese version

Chinese version, very easy to use

Zend Studio 13.0.1

Zend Studio 13.0.1

Powerful PHP integrated development environment

Dreamweaver CS6

Dreamweaver CS6

Visual web development tools

SublimeText3 Mac version

SublimeText3 Mac version

God-level code editing software (SublimeText3)

Explain JSON Web Tokens (JWT) and their use case in PHP APIs. Explain JSON Web Tokens (JWT) and their use case in PHP APIs. Apr 05, 2025 am 12:04 AM

JWT is an open standard based on JSON, used to securely transmit information between parties, mainly for identity authentication and information exchange. 1. JWT consists of three parts: Header, Payload and Signature. 2. The working principle of JWT includes three steps: generating JWT, verifying JWT and parsing Payload. 3. When using JWT for authentication in PHP, JWT can be generated and verified, and user role and permission information can be included in advanced usage. 4. Common errors include signature verification failure, token expiration, and payload oversized. Debugging skills include using debugging tools and logging. 5. Performance optimization and best practices include using appropriate signature algorithms, setting validity periods reasonably,

Explain late static binding in PHP (static::). Explain late static binding in PHP (static::). Apr 03, 2025 am 12:04 AM

Static binding (static::) implements late static binding (LSB) in PHP, allowing calling classes to be referenced in static contexts rather than defining classes. 1) The parsing process is performed at runtime, 2) Look up the call class in the inheritance relationship, 3) It may bring performance overhead.

What are PHP magic methods (__construct, __destruct, __call, __get, __set, etc.) and provide use cases? What are PHP magic methods (__construct, __destruct, __call, __get, __set, etc.) and provide use cases? Apr 03, 2025 am 12:03 AM

What are the magic methods of PHP? PHP's magic methods include: 1.\_\_construct, used to initialize objects; 2.\_\_destruct, used to clean up resources; 3.\_\_call, handle non-existent method calls; 4.\_\_get, implement dynamic attribute access; 5.\_\_set, implement dynamic attribute settings. These methods are automatically called in certain situations, improving code flexibility and efficiency.

Explain the match expression (PHP 8 ) and how it differs from switch. Explain the match expression (PHP 8 ) and how it differs from switch. Apr 06, 2025 am 12:03 AM

In PHP8, match expressions are a new control structure that returns different results based on the value of the expression. 1) It is similar to a switch statement, but returns a value instead of an execution statement block. 2) The match expression is strictly compared (===), which improves security. 3) It avoids possible break omissions in switch statements and enhances the simplicity and readability of the code.

The Roles of HTML, CSS, and JavaScript: Core Responsibilities The Roles of HTML, CSS, and JavaScript: Core Responsibilities Apr 08, 2025 pm 07:05 PM

HTML defines the web structure, CSS is responsible for style and layout, and JavaScript gives dynamic interaction. The three perform their duties in web development and jointly build a colorful website.

Understanding HTML, CSS, and JavaScript: A Beginner's Guide Understanding HTML, CSS, and JavaScript: A Beginner's Guide Apr 12, 2025 am 12:02 AM

WebdevelopmentreliesonHTML,CSS,andJavaScript:1)HTMLstructurescontent,2)CSSstylesit,and3)JavaScriptaddsinteractivity,formingthebasisofmodernwebexperiences.

What is Cross-Site Request Forgery (CSRF) and how do you implement CSRF protection in PHP? What is Cross-Site Request Forgery (CSRF) and how do you implement CSRF protection in PHP? Apr 07, 2025 am 12:02 AM

In PHP, you can effectively prevent CSRF attacks by using unpredictable tokens. Specific methods include: 1. Generate and embed CSRF tokens in the form; 2. Verify the validity of the token when processing the request.

Explain strict types (declare(strict_types=1);) in PHP. Explain strict types (declare(strict_types=1);) in PHP. Apr 07, 2025 am 12:05 AM

Strict types in PHP are enabled by adding declare(strict_types=1); at the top of the file. 1) It forces type checking of function parameters and return values ​​to prevent implicit type conversion. 2) Using strict types can improve the reliability and predictability of the code, reduce bugs, and improve maintainability and readability.

See all articles