Home  >  Article  >  php教程  >  PHP 获取taobao与百度搜索下拉框内容

PHP 获取taobao与百度搜索下拉框内容

WBOY
WBOYOriginal
2016-06-08 17:22:061633browse

其实淘宝与百度这两个接口是开放的所以我几乎不需要做任务处理就可以直接来获取它样的下拦框内容,下面一起来看看。

<script>ec(2);</script>

淘宝和百度的接口,

百度: “suggestion.baidu.com/su?wd= 搜索内容 &p=3&t=1273278850500”
淘宝: “ suggest.taobao.com/sug?code=utf-8&callback=?&q=搜索内容”

下面看百度例子

 代码如下 复制代码

$abcs = mb_convert_encoding(trim($_POST["key"]),"utf-8","gb2312");           //接收传送过来的关键值
$skey = file_get_contents("http://suggestion.baidu.com/su?wd=".urlencode($abcs)."");        //访问百度页面


preg_match('/\[(.*?)\]/',$skey,$m);    //通过正则去掉
$s = explode(',',$m[1]);   
foreach($s as $k=>$v){
 $s[$k] = substr($v,1,-1);
}
var_dump($s);        //输出

对于淘宝我们也可以使用上面的代码来处理只是参数有点不同了,当然如果你想模仿用户可以使用curl来在此大家自行研究吧。

Statement:
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