每天学习一点点,每天进步一点点.
login

Php正则爬虫

2015-06-08 16:22:00  |  分类: Php |  标签: 无 阅读(2508)    评论(0)
  1. //如果出现中文乱码使用下面代码
  2. //$getcontent = iconv("gb2312", "utf-8",$contents);
  3. <?php
  4. $url = 'http://sintegrate.tmall.com/category-939626514.htm'; //这儿填页面地址
  5. $info=file_get_contents($url);
  6. preg_match('|<p class="price">¥<span>(.*?)<\/span><\/p>|i',$info,$m);
  7. echo $m[1];
  8. ?>
  9. <?php
  10. $url = 'http://www.baidu.com'; //这儿填页面地址
  11. $info=file_get_contents($url);
  12. preg_match('|<title>(.*?)<\/title>|i',$info,$m);
  13. echo $m[1];
  14. ?>
留言区域