PHP implements grabbing Taobao product price popularity source code

WBOY
Release: 2016-07-29 09:04:33
Original
1783 people have browsed it

I was bored at home during the winter vacation and wanted to see what Taobao-related development was like. I registered as a Taobao developer, and then when I wanted to adjust the API, I found that there were many complicated steps, and some of them were charged. It was so annoying, so I tried to capture some Taobao data and made my own API.

Getting product popularity, that is, the number of collectors, currently only supports Taobao products, not Tmall. Obtaining popularity and product names are supported by both Taobao and Tmall, but because it is a cached file of Taobao, so. . . There may be some problems, but I haven't encountered any problems during testing.

If you find any problems during use, please contact me and I will make improvements.

My contact information:

  • Weibo: http://weibo.com/578013333
  • E-mail: leiflyy@outlook.com

At the same time, I am also planning to do some other things, such as the achieved acquisition I don’t think the product pictures are very useful. . . So, I’ll add it to the next edition.

Okay, no more nonsense, here’s the source code

/** * Created by PhpStorm. * User: leif * Date: 16/1/26 * Time: 10:17 * email: leiflyy@outlook.com *//** * 实现传入宝贝的id,返回宝贝的链接,支持淘宝 * @param $id 宝贝的id * @return string 返回的宝贝的链接 */functiongetTbLink($id){$url="https://item.taobao.com/item.htm?spm=a1z10.4-c.w5003-12641268955.30.0lDnKZ&id=".$id."&scene=taobao_shop"; return$url; } /** * 实现传入宝贝的id,获取宝贝的商品名,支持淘宝和天猫 * @param $id 宝贝的id * @return mixed 宝贝的商品名 */functiongetNameById($id){$url="http://hws.m.taobao.com/cache/wdetail/5.0/?id=".$id; $content=file_get_contents($url); $content_ori=strip_tags($content); $content_arr=json_decode($content_ori,true); $detail=json_decode($content_arr['data']['apiStack']['0']['value'],true); $success_sym=$detail['ret']['0'];//成功则返回"SUCCESS::调用成功";if($success_sym=="SUCCESS::调用成功"){ $name=$content_arr['data']['itemInfoModel']['title']; return$name; }else{ return""; } } /** * 实现传入宝贝id,获取宝贝价格,支持淘宝和天猫 * @param $id 宝贝的id * @return mixed 返回的宝贝的价格或价格区间 */functiongetPriceById($id){$url="http://hws.m.taobao.com/cache/wdetail/5.0/?id=".$id; $content=file_get_contents($url); $content_ori=strip_tags($content); $content_arr=json_decode($content_ori,true); $pro_detail=json_decode($content_arr['data']['apiStack']['0']['value'],true); $success_sym=$pro_detail['ret']['0'];//成功则返回"SUCCESS::调用成功";if($success_sym=="SUCCESS::调用成功"){ $pro_price=$pro_detail['data']['itemInfoModel']['priceUnits']['0']['price']; return$pro_price; }else{ return""; } } /** * 实现传入宝贝id,获取宝贝的收藏人数(人气),支持淘宝 * @param $id 宝贝id * @return mixed 返回的宝贝的收藏人数(人气) */functiongetPopById($id){$url=getTbLink($id); $urlinfo = parse_url($url); parse_str($urlinfo['query'], $query); $id = $query['id']; $data = file_get_contents($url); $start = strpos($data, 'counterApi'); $start = strpos($data, ": ", $start); $end = strpos($data, "',", $start); $api = 'https:' . substr($data, $start + 3, $end - $start - 3) . '&callback=jsonp107'; $response = file_get_contents($api); $response = substr($response, 9, -2); $arr = json_decode($response, true); $popularity=$arr['ICCP_1_'.$id]; return$popularity; }
Copy after login
').addClass('pre-numbering').hide(); $(this).addClass('has-numbering').parent().append($numbering); for (i = 1; i ').text(i)); }; $numbering.fadeIn(1700); }); });

The above introduces the PHP source code for capturing Taobao product prices and popularity, including relevant content. I hope it will be helpful to friends who are interested in PHP tutorials.

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
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!