将百度搜索结果链接转为实际链接

WBOY
Release: 2016-06-20 13:03:51
Original
1971 people have browsed it

最近百度动作挺大的,搜索算法频繁调整。刚才在分析本站百度收录情况的时候又发现百度的搜索结果连接竟然也变了,想必这么做是对付360恶意抓取百度的搜索结果的吧。没办法,百度变了,俺这收录分析工具也得跟着变一变了,总得将这奇长无比的链接转为正常的链接才行吧!

研究了一下,发现还是可以转变的。

<p>function getRealUrl($url){</p>	$header=get_headers($url,1);<br />	if (strpos($header[0],'301')||strpos($header[0],'302')){<br />		if(is_array($header['Location'])){<br />			return $header['Location'][count($header['Location'])-1];<br />		}else{<br />			return $header['Location'];<br />		}<br />	}else{<br />		return $url;<br />	}<br />}例如下面这个例子:<?php<br />header('Content-type:text/html;charset=utf-8');<br />function getRealUrl($url){<br />	$header=get_headers($url,1);<br />	if (strpos($header[0],'301')||strpos($header[0],'302')){<br />		if(is_array($header['Location'])){<br />			return $header['Location'][count($header['Location'])-1];<br />		}else{<br />			return $header['Location'];<br />		}<br />	}else{<br />		return $url;<br />	}<br />}<br />$url='http://www.baidu.com/link?url=nuQ4reDIkrTCHpWQQXJpTC_GSLEUrk6Bb6WmCMZqaLHES2LUiv98OaiKZjvjz8xx';<br /><br />$url=getRealUrl($url);<br />echo '真实的url为:'.$url;
Copy after login


Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!