10月52014
php采集百度某关键词搜索结果的网址
<?php /** * 采集某百度某关键词搜索结果的网址
* @param str $keyword 关键词
* @return array $result 搜索结果网址数组
*/
function baidu_keyword_fpage($keyword) {
// 组成搜索url
$url = 'http://www.baidu.com/s?word=' . $keyword;
$html = file_get_contents($url);
$search = '/<span class="g">(.*?)<\/span>/i';
preg_match_all($search, $html, $r);
return $r;
}
if(isset($_GET[q])) {
$url = $_GET[q];
$urlarray = baidu_keyword_fpage($url);
}
?>
<html>
<head>
<title>查询百度关键词结果网址</title>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312" />
</head>
<body>
<form method="get" action="">
请输入关键词:<br />
<input type="text" name="q" value="<?php echo $url; ?>"><input type="submit" value="查 询">
</form>
<br />
<?php
echo '<pre>';
print_r($urlarray[1]);
echo '</pre>';
?>
</body>
</html>
发表评论
木有头像就木JJ啦!还木有头像吗?点这里申请属于你的个性Gravatar头像吧!