php获取百度相关搜索,PHP获取百度相关搜索和原创程度_PHP教程

本文介绍如何使用PHP从百度获取相关搜索结果,并通过get_em_times函数计算关键词原创度,以优化搜索引擎。get_em_times函数根据文本频率衡量原创性,数值越高,文本越不独特。

PHP获取百度相关搜索和原创程度

获取原创程度是get_em_times,数值越高文本长度越长越不原创。

用于采集项目的搜索引擎优化

class baidu {

public static function build_request_uri($words){

$words = urlencode(Text::convert_encoding($words,GBK,UTF-8));

return /s?wd=.$words;

}

public static function get_relate_search($words){

$content = self::get_content($words);

if(preg_match(/

(((?!).)*)/, $content,$result)){

if(preg_match_all(/).)*>(.*?)/, $result[1], $result)) return $result[2];

}

return FALSE;

}

/**

* 根据空格分词,获取百度关键词完全匹配的次数

* @param string $words

* @return int

*/

public static function get_em_times($words){

$word = explode( , $words);

$content = self::get_content($words);

preg_match_all(/(((?!).)*)/, $content,$result);

if(!isset($result[1]) || count($result[1])==0)

return 0;

$word_table = array_count_values($result[1]);

$times = 0;

foreach ($word as $pice){

if(array_key_exists($pice, $word_table)) $times+=$word_table[$pice];

}

return $times;

}

public static function get_content($words){

static $loaded_contents = array();

if(!isset($loaded_contents[$words])){

$content = file_get_contents("http://www.baidu.com".self::build_request_uri($words));

$content = Text::convert_encoding($content,UTF-8,GBK);

$loaded_contents[$words] = $content;

}

return $loaded_contents[$words];

}

function check_veriy($content){

if(strpos($content,"http://verify.baidu.com/")!==FALSE){

//百度要求验证,异常

}

}

}

http://www.bkjia.com/PHPjc/486027.htmlwww.bkjia.comtruehttp://www.bkjia.com/PHPjc/486027.htmlTechArticlePHP获取百度相关搜索和原创程度 获取原创程度是get_em_times,数值越高文本长度越长越不原创。 用于采集项目的搜索引擎优化 class baidu { p...

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值