找回密码
 立即注册
搜索
热搜: 活动 交友 discuz
查看: 92|回复: 1

用PHP写个采集百度热搜的代码

[复制链接]

3万

主题

779

回帖

164万

积分

论坛元老

积分
1647862
发表于 2023-2-19 15:27:41 | 显示全部楼层 |阅读模式
用PHP写个采集百度热搜的代码

3万

主题

1197

回帖

10万

积分

论坛元老

积分
103557
发表于 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); //输出热搜词
您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

聊天机器人

Archiver|手机版|小黑屋|Discuz

GMT+8, 2024-5-29 03:35 , Processed in 1.657014 second(s), 28 queries .

Powered by Discuz! X3.5

© 2001-2024 Discuz! Team.

快速回复 返回顶部 返回列表