帮助你我他,遇到网站问题怎么办:找它帮你网
当前位置:主页 > 后台编程语言 > PHP教程 >

利用php的curl函数采集百度top关键词

时间:2022-01-21 08:20:34|来源:网络精心整理

最近站群,需要收集一些关键词和标题,找来找去发现top.baidu.com里面的关键词和标题不错,就像把它复制下来,但一条一条去复制,太麻烦,于是用php的curl函数,写了一个小工具,输入网址可以采集到关键词,效果如下图所示:




这样直接就可以,获取到想要的标题,好了全部代码如下,复制到一个php文件中,再网站中运行即可:
 

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312" />
<title>百度热点标题提取</title>
</head>

<body>
<div>
<form action="" method="post">
<input type="text" style="width:500px;" name="url"/>
<input type="submit" value="提交" /> 
<input type="button" value="复制" id="fuzhi" /> 
</div>
<?php

$url=$_POST['url'];
if(!empty($url))
{

$curl = curl_init();

//$url='http://top.baidu.com/buzz?b=1&fr=topindex';

//设置请求url

curl_setopt($curl, CURLOPT_URL,$url );

//是否将头文件输出

curl_setopt($curl, CURLOPT_HRADER,TRUE );

// 设置cURL 参数,要求结果保存到字符串中还是输出到屏幕上。

curl_setopt($curl, CURLOPT_RETURNTRANSFER,TRUE );

// 运行cURL,请求网页

$data = curl_exec($curl);

// 关闭URL请求
curl_close($curl);

preg_match_all('/<a(.*?)class="list-title"(.*?)>(.*?)</a>/i',$data,$matches);

foreach($matches[3] as $key=>$value)
{
	$sj.=$value.'&#10';
}
}

?>
<div>
<textarea id="jg" style="height:800px; width:600px;"><?php echo $sj ?></textarea>
</div>
 <script src="/uploads/allimg/190703/142F24214-1.jpg"></script>
<script>
$("#fuzhi").click(function(){
	$("#jg").select();
	try {
        var successful = document.execCommand('copy');
        var msg = successful ? '成功复制到剪贴板' : '该浏览器不支持点击复制到剪贴板';
       alert(msg);
      } catch (err) {
        alert('该浏览器不支持点击复制到剪贴板');
      }	
	})
</script>
</body>
</html>
 

上一篇:php如何上传txt文件,并且读取txt文件

下一篇:PHP读txt文件 一次随机读一行

本文标题:利用php的curl函数采集百度top关键词

本文地址:https://www.tabangni.com/phpstudy/210.html

查看更多与“highlight.js”有关的文章



重要申明:本站所有的文章均收集自网络,与本站立场无关。

如果侵犯了您的权利,请与我们联系,我们将在24小时内进行处理、任何非本站因素导致的法律后果,本站均不负任何责任。

Copyright © 2017-2021 它帮你网 版权所有 豫ICP备17031272号-3