Rumah >php教程 >PHP源码 >批量下载搜狗词库

批量下载搜狗词库

PHP中文网
PHP中文网asal
2016-05-25 17:06:422095semak imbas

批量下载,搜狗词库  

<?php
    /*//echo microtime();
    echo $start=strtotime(date("Y-m-01"))."<br/>";
    echo urlencode(iconv("UTF-8","GB2312//IGNORE","中国的") );
    echo urlencode("/");
    require_once "pinyin.php";
    $pinyin=new PY_deal();
    echo join($pinyin->pinyin("麦包包批发,[魅惑/微光摇曳/青春密语]三种款式,自由选择!现只需50元/款!"));*/
 
    $fp=fopen("dictory.txt", "a+");
    for($i=1;$i<=4;$i++){
        $curl=curl_init();
        $url="http://pinyin.sogou.com/dict/search.php?
        word=%B0%A2%C0%EF%B0%CD%B0%CD%B2%FA%C6%B7%B4%CA%BB%E3&type=0&personal=1&page={$i}";
        $options=array(CURLOPT_URL=>$url,CURLOPT_RETURNTRANSFER=>true,CURLOPT_HEADER=>false);
        curl_setopt_array($curl, $options);
        $rs=curl_exec($curl);
        curl_close($curl);
        $pattern_list="/\<dl\s+class\=\"dictlist\"\>([\S\s]+)?\<\/dl\>/i";
        preg_match_all($pattern_list,$rs,$match);
        $rs=$match[1][0];
        $pattern="/\?id=(\d+?)\"/i";
        preg_match_all($pattern,$rs,$match);
        $rs=$match[1];
         
        foreach($rs as $v){
            $link="http://pinyin.sogou.com/dict/download_txt.php?id={$v}";
            $curl=curl_init();
            $options=array(CURLOPT_URL=>$link,CURLOPT_FILE=>$fp,CURLOPT_HEADER=>false);
            curl_setopt_array($curl, $options);
            curl_exec($curl);
            curl_close($curl);
             
 
        }
 
    }
     
 
    fclose($fp);
?>

                                                         

2. PHP代码 

$fp=fopen("dictory.txt", "a+");
    for($i=1;$i<=4;$i++){
        $curl=curl_init();
        $url="http://pinyin.sogou.com/dict/search.php?
        word=%B0%A2%C0%EF%B0%CD%B0%CD%B2%FA%C6%B7%B4%CA%BB%E3&type=0&personal=1&page={$i}";
        $options=array(CURLOPT_URL=>$url,CURLOPT_RETURNTRANSFER=>true,CURLOPT_HEADER=>false);
        curl_setopt_array($curl, $options);
        $rs=curl_exec($curl);
        curl_close($curl);
        $pattern_list="/\<dl\s+class\=\"dictlist\"\>([\S\s]+)?\<\/dl\>/i";
        preg_match_all($pattern_list,$rs,$match);
        $rs=$match[1][0];
        $pattern="/\?id=(\d+?)\"/i";
        preg_match_all($pattern,$rs,$match);
        $rs=$match[1];
         
        foreach($rs as $v){
            $link="http://pinyin.sogou.com/dict/download_txt.php?id={$v}";
            $curl=curl_init();
            $options=array(CURLOPT_URL=>$link,CURLOPT_FILE=>$fp,CURLOPT_HEADER=>false);
            curl_setopt_array($curl, $options);
            curl_exec($curl);
            curl_close($curl);
             
 
        }
 
    }
     
 
    fclose($fp);

           

以上就是批量下载搜狗词库的内容,更多相关内容请关注PHP中文网(www.php.cn)!


       

Kenyataan:
Kandungan artikel ini disumbangkan secara sukarela oleh netizen, dan hak cipta adalah milik pengarang asal. Laman web ini tidak memikul tanggungjawab undang-undang yang sepadan. Jika anda menemui sebarang kandungan yang disyaki plagiarisme atau pelanggaran, sila hubungi admin@php.cn
Artikel sebelumnya:可让软件读取更新的PHP页面Artikel seterusnya:php登录代码