# php获取google搜索结果

**URL:** <https://forum.90sec.com/t/topic/3786>\
**Category:** 工具资源\
**Created:** [2012 年6 月 25 日 15:06 UTC](https://forum.90sec.com/t/topic/3786 "2012-06-25T15:06:27Z")\
**Posts on this page:** 7\
**Page:** 1

<div class="post-metadata">

作者： ![jjf012](https://forum.90sec.com/letter_avatar_proxy/v4/letter/j/b5a626/32.png) [@jjf012](https://forum.90sec.com/u/jjf012)\
发布日期： [2012 年6 月 25 日 15:06 UTC](https://forum.90sec.com/t/topic/3786/1 "2012-06-25T15:06:27Z")

</div>

_本帖最后由 jjf012 于 2012-6-25 23:08 编辑_

```php
<?php
$keyword='inurl:edu.cn/news.php?id=';
$startpage = 1;
$lastpage = 2;
header('Content-Type: text/html; charset=utf-8');
$cookie_file = dirname( __FILE__ ).'/cookie.txt';
//$cookie_file = tempnam("tmp","cookie");
 
//先获取cookies并保存
$url = "http://www.google.com.hk";
$ch = curl_init($url); //初始化
curl_setopt($ch, CURLOPT_HEADER, 0); //不返回header部分
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); //返回字符串，而非直接输出
curl_setopt($ch, CURLOPT_COOKIEJAR, $cookie_file); //存储cookies
curl_exec($ch);
curl_close($ch);

for($i=$startpage;$i<$lastpage;$i++){
	$array = readGoogle($keyword, $i,0);//1表示只获取主机名，反之则获取网址链接
		foreach ($array as $key=>$url){
		$url_list = file('url.txt');
		if (in_array("$url\r\n", $url_list)){
			echo "[-] Links repeat, in page $i line $key<br />\n";
		}else{
			$fp = @fopen('url.txt', 'a'); //写入文件前判断是否重复
			@fwrite($fp, $url."\r\n");
			@fclose($fp);
		}
	}
}
////使用上面保存的cookies再次访问
function readGoogle($keyword,$nowpage,$sign){
$url = "http://www.google.com.hk/search?q=".urlencode($keyword)."&&oe=gb2312&hl=zh-CN&safe=off&num=20&start=".$nowpage;
$ch = curl_init($url);
curl_setopt($ch, CURLOPT_HEADER, 0);
curl_setopt($ch, CURLOPT_USERAGENT, 'Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1)');
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_BINARYTRANSFER, true);
curl_setopt($ch, CURLOPT_COOKIEFILE, 'cookie.txt'); //使用上面获取的cookies
$response = curl_exec($ch);
curl_close($ch);
preg_match_all("/<cite>(.*?)<\/cite>/" ,$response, $res);
$num = count($res[1]);
for($i=0;$i<$num;$i++){
	$res[1][$i] = str_replace('<b>','',$res[1][$i]);
	$res[1][$i] = str_replace('</b>','',$res[1][$i]);
	if($sign==1){
	$row = explode('/', $res[1][$i]);
	$res[1][$i] = $row[0];
	}
}
return $res[1];
}

?>

```

[http://www.google.com.hk](http://www.google.com.hk)  
[http://www.google.com.hk/search?q=".urlencode($keyword)."&&oe=gb2312&hl=zh-CN&safe=off&num=20&start=](http://www.google.com.hk/search?q=%22.urlencode($keyword).%22&&oe=gb2312&hl=zh-CN&safe=off&num=20&start=)  

原来google搜索是跟百度不一样的。。所以重新写了。  
结合网上修改而来，可用。{:4\_51:} 算作伪原创吧。  
谷歌百度均已解决。。接下来研究别人写的exp了……

---

<div class="post-metadata">

作者： ![winy](https://forum.90sec.com/user_avatar/forum.90sec.com/winy/32/11446_2.png) [@winy](https://forum.90sec.com/u/winy)\
发布日期： [2012 年6 月 25 日 16:31 UTC](https://forum.90sec.com/t/topic/3786/2 "2012-06-25T16:31:15Z")

</div>

不太清楚你用PHP实现这种功能的目的是？？{:4\_57:}

---

<div class="post-metadata">

作者： ![mOon](https://forum.90sec.com/letter_avatar_proxy/v4/letter/m/f07891/32.png) [@mOon](https://forum.90sec.com/u/mOon)\
发布日期： [2012 年6 月 25 日 17:25 UTC](https://forum.90sec.com/t/topic/3786/3 "2012-06-25T17:25:04Z")

</div>

\*\*回复 [2#](http://www.90sec.org/redirect.php?goto=findpost&pid=32525&ptid=2810) _winy_ \*\*

```
批量日站

```

---

<div class="post-metadata">

作者： ![user48](https://forum.90sec.com/letter_avatar_proxy/v4/letter/u/bc8723/32.png) [@user48](https://forum.90sec.com/u/user48)\
发布日期： [2012 年6 月 25 日 18:22 UTC](https://forum.90sec.com/t/topic/3786/4 "2012-06-25T18:22:05Z")

</div>

网站猎手，的exe程序个人感觉不错，批量从百度获取url地址。然后导出，也能批量日。

---

<div class="post-metadata">

作者： ![jjf012](https://forum.90sec.com/letter_avatar_proxy/v4/letter/j/b5a626/32.png) [@jjf012](https://forum.90sec.com/u/jjf012)\
发布日期： [2012 年6 月 26 日 01:27 UTC](https://forum.90sec.com/t/topic/3786/5 "2012-06-26T01:27:02Z")

</div>

> 不太清楚你用PHP实现这种功能的目的是？？  
> winy 发表于 2012-6-26 00:31 [[img][http://www.90sec.org/images/common/back.gif[/img\]](http://www.90sec.org/images/common/back.gif%5B/img%5C%5D)]([http://www.90sec.org/redirect.php?goto=findpost&pid=32525&ptid=2810](http://www.90sec.org/redirect.php?goto=findpost&pid=32525&ptid=2810))

```
看能不能全自动日站。。

```

---

<div class="post-metadata">

作者： ![beastk](https://forum.90sec.com/letter_avatar_proxy/v4/letter/b/7feea3/32.png) [@beastk](https://forum.90sec.com/u/beastk)\
发布日期： [2012 年6 月 26 日 01:30 UTC](https://forum.90sec.com/t/topic/3786/6 "2012-06-26T01:30:58Z")

</div>

谷歌被天朝之后就不太行勒

---

<div class="post-metadata">

作者： ![winy](https://forum.90sec.com/user_avatar/forum.90sec.com/winy/32/11446_2.png) [@winy](https://forum.90sec.com/u/winy)\
发布日期： [2012 年6 月 26 日 02:24 UTC](https://forum.90sec.com/t/topic/3786/7 "2012-06-26T02:24:06Z")

</div>

\*\*回复 [3#](http://www.90sec.org/redirect.php?goto=findpost&pid=32531&ptid=2810) _darkmoon_ \*\*

```
关键是获取了gg的结果，怎么用php自动分析结果中的站点让不让日?期待LZ下一步的动作{:4_97:}

```
