Home > Backend Development > PHP Tutorial > PHP crawls web pages to match content templates

PHP crawls web pages to match content templates

WBOY
Release: 2016-08-08 09:29:38
Original
1462 people have browsed it
<?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(&#39;/<div class="resitem"(.*)<\/div>/iUs',$content,$text);//用正则表达式匹配搜索结果
  //var_dump($text);
  foreach ($text[0] as $key) 
  {
    echo $key."<br>";
  }
?>
Copy after login

The above introduces the matching content template for php crawling web pages, including aspects of content. I hope it will be helpful to friends who are interested in PHP tutorials.

Related labels:
source:php.cn
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
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template