Heim >Backend-Entwicklung >PHP-Tutorial >php抓取网页婚配内容模板
php抓取网页匹配内容模板
<?php set_time_limit(0); $url="http://wap.baidu.com/s?word=site%3Apan.baidu.com+intitle%3A%E5%85%8D%E8%B4%B9%E9%AB%98%E9%80%9F"; //百度搜索结果 $ch=curl_init(); curl_setopt($ch,CURLOPT_HEADER,false); curl_setopt($ch,CURLOPT_URL,$url); curl_setopt($ch,CURLOPT_RETURNTRANSFER,1); $content=curl_exec($ch); curl_close($ch); preg_match_all('/<div class="resitem"(.*)<\/div>/iUs',$content,$text);//用正则表达式匹配搜索结果 //var_dump($text); foreach ($text[0] as $key) { echo $key."<br>"; }?>