PHP 采集

<?php

header("content-type:text/html;charset=gbk");

// 要采集的页面的地址

$url = "http://www.2cloo.com/hot";

// 获取页面内容

$url_content = file_get_contents( $url );

// 将页面内容保存在本地

file_put_contents('caiji.html', $url_content);

// 从本地的获取内容

$content = file_get_contents( 'caiji.html' );

// 确定要匹配内容的正则

$preg_content = '|<strong>(.*?)</strong>|i';

// 正则匹配 获取到需要的内容

preg_match_all($preg_content, $url_content, $data);

print_r( $data );

?>

原文地址:https://www.cnblogs.com/laowenBlog/p/5916678.html