|
发表于 2023-2-19 15:28:55
|
显示全部楼层
/**
* 采集百度热搜
*/
$url = "http://top.baidu.com/";//设置需要采集的网址
$html = file_get_contents($url);//将网站源代码存入$html变量中
//正则表达式,从网页源代码中匹配出所有的热搜词
$pattern = '/<a target=\"_blank\"\s+href=\".*?\"\s+class=\"list-title\">(.*?)<\/a>/';
preg_match_all($pattern, $html, $matches); //将匹配的结果存入$matches数组
$keywords = $matches[1]; //将匹配的热搜词存入$keywords数组
print_r($keywords); //输出热搜词 |
|