PHP擷取百度相關搜尋和原創程度_PHP教程

來源:互聯網
上載者:User
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...

  • 聯繫我們

    該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

    如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

    A Free Trial That Lets You Build Big!

    Start building with 50+ products and up to 12 months usage for Elastic Compute Service

    • Sales Support

      1 on 1 presale consultation

    • After-Sales Support

      24/7 Technical Support 6 Free Tickets per Quarter Faster Response

    • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.