search
HomeBackend DevelopmentPHP TutorialPHP implements grabbing Taobao product price popularity source code

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

<code><span><span><?php </span><span>/**
 * Created by PhpStorm.
 * User: leif
 * Date: 16/1/26
 * Time: 10:17
 * email: leiflyy@outlook.com
 */</span><span>/**
 *  实现传入宝贝的id,返回宝贝的链接,支持淘宝
 *<span> @param</span> $id 宝贝的id
 *<span> @return</span> string 返回的宝贝的链接
 */</span><span><span>function</span><span>getTbLink</span><span>(<span>$id</span>)</span>{</span><span>$url</span>=<span>"https://item.taobao.com/item.htm?spm=a1z10.4-c.w5003-12641268955.30.0lDnKZ&id="</span>.<span>$id</span>.<span>"&scene=taobao_shop"</span>;
    <span>return</span><span>$url</span>;
}


<span>/**
 * 实现传入宝贝的id,获取宝贝的商品名,支持淘宝和天猫
 *<span> @param</span> $id  宝贝的id
 *<span> @return</span> mixed  宝贝的商品名
 */</span><span><span>function</span><span>getNameById</span><span>(<span>$id</span>)</span>{</span><span>$url</span>=<span>"http://hws.m.taobao.com/cache/wdetail/5.0/?id="</span>.<span>$id</span>;
    <span>$content</span>=file_get_contents(<span>$url</span>);
    <span>$content_ori</span>=strip_tags(<span>$content</span>);
    <span>$content_arr</span>=json_decode(<span>$content_ori</span>,<span>true</span>);
    <span>$detail</span>=json_decode(<span>$content_arr</span>[<span>'data'</span>][<span>'apiStack'</span>][<span>'0'</span>][<span>'value'</span>],<span>true</span>);
    <span>$success_sym</span>=<span>$detail</span>[<span>'ret'</span>][<span>'0'</span>];<span>//成功则返回"SUCCESS::调用成功";</span><span>if</span>(<span>$success_sym</span>==<span>"SUCCESS::调用成功"</span>){
        <span>$name</span>=<span>$content_arr</span>[<span>'data'</span>][<span>'itemInfoModel'</span>][<span>'title'</span>];
        <span>return</span><span>$name</span>;
    }<span>else</span>{
        <span>return</span><span>"<script type="text/javascript">alert('宝贝不存在!');</script>"</span>;
    }

}

<span>/**
 * 实现传入宝贝id,获取宝贝价格,支持淘宝和天猫
 *<span> @param</span> $id   宝贝的id
 *<span> @return</span> mixed 返回的宝贝的价格或价格区间
 */</span><span><span>function</span><span>getPriceById</span><span>(<span>$id</span>)</span>{</span><span>$url</span>=<span>"http://hws.m.taobao.com/cache/wdetail/5.0/?id="</span>.<span>$id</span>;
    <span>$content</span>=file_get_contents(<span>$url</span>);
    <span>$content_ori</span>=strip_tags(<span>$content</span>);
    <span>$content_arr</span>=json_decode(<span>$content_ori</span>,<span>true</span>);
    <span>$pro_detail</span>=json_decode(<span>$content_arr</span>[<span>'data'</span>][<span>'apiStack'</span>][<span>'0'</span>][<span>'value'</span>],<span>true</span>);
    <span>$success_sym</span>=<span>$pro_detail</span>[<span>'ret'</span>][<span>'0'</span>];<span>//成功则返回"SUCCESS::调用成功";</span><span>if</span>(<span>$success_sym</span>==<span>"SUCCESS::调用成功"</span>){
        <span>$pro_price</span>=<span>$pro_detail</span>[<span>'data'</span>][<span>'itemInfoModel'</span>][<span>'priceUnits'</span>][<span>'0'</span>][<span>'price'</span>];
        <span>return</span><span>$pro_price</span>;
    }<span>else</span>{
        <span>return</span><span>"<script type="text/javascript">alert('宝贝不存在!');</script>"</span>;
    }
}

<span>/**
 *  实现传入宝贝id,获取宝贝的收藏人数(人气),支持淘宝
 *<span> @param</span> $id  宝贝id
 *<span> @return</span> mixed   返回的宝贝的收藏人数(人气)
 */</span><span><span>function</span><span>getPopById</span><span>(<span>$id</span>)</span>{</span><span>$url</span>=getTbLink(<span>$id</span>);
    <span>$urlinfo</span> = parse_url(<span>$url</span>);
    parse_str(<span>$urlinfo</span>[<span>'query'</span>], <span>$query</span>);
    <span>$id</span> = <span>$query</span>[<span>'id'</span>];
    <span>$data</span> = file_get_contents(<span>$url</span>);
    <span>$start</span> = strpos(<span>$data</span>, <span>'counterApi'</span>);
    <span>$start</span> = strpos(<span>$data</span>, <span>": "</span>, <span>$start</span>);
    <span>$end</span> = strpos(<span>$data</span>, <span>"',"</span>, <span>$start</span>);
    <span>$api</span> = <span>'https:'</span> . substr(<span>$data</span>, <span>$start</span> + <span>3</span>, <span>$end</span> - <span>$start</span> - <span>3</span>) . <span>'&callback=jsonp107'</span>;
    <span>$response</span> = file_get_contents(<span>$api</span>);
    <span>$response</span> = substr(<span>$response</span>, <span>9</span>, -<span>2</span>);
    <span>$arr</span> = json_decode(<span>$response</span>, <span>true</span>);
    <span>$popularity</span>=<span>$arr</span>[<span>'ICCP_1_'</span>.<span>$id</span>];
    <span>return</span><span>$popularity</span>;
}</span></span></code>
').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.

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
此 Apple ID 尚未在 iTunes Store 中使用:修复此 Apple ID 尚未在 iTunes Store 中使用:修复Jun 10, 2024 pm 05:42 PM

使用AppleID登录iTunesStore时,可能会在屏幕上抛出此错误提示“此AppleID尚未在iTunesStore中使用”。没有什么可担心的错误提示,您可以按照这些解决方案集进行修复。修复1–更改送货地址此提示出现在iTunesStore中的主要原因是您的AppleID个人资料中没有正确的地址。步骤1–首先,打开iPhone上的iPhone设置。步骤2–AppleID应位于所有其他设置的顶部。所以,打开它。步骤3–在那里,打开“付款和运输”选项。步骤4–使用面容ID验证您的访问权限。步骤

修复事件ID 55,50,98,140磁盘错误在事件查看器修复事件ID 55,50,98,140磁盘错误在事件查看器Mar 19, 2024 am 09:43 AM

若您在Windows11/10的事件查看器中发现事件ID55、50、140或98,或遇到磁盘文件系统结构损坏且无法使用的错误,请按照以下指南解决此问题。什么是事件55,磁盘上的文件系统结构损坏和不可用的意思?第55届会议,Ntfs磁盘上的文件系统结构损坏且无法使用。请在卷上运行chkMSK实用程序当NTFS无法将数据写入事务日志时,会触发事件ID55的错误,这将导致NTFS无法完成无法写入事务数据的操作。这种错误通常发生在文件系统损坏的情况下,可能是由于磁盘上存在坏扇区或文件系统对磁盘子系统的不

阿里巴巴id在哪里看阿里巴巴id在哪里看Mar 08, 2024 pm 09:49 PM

在阿里巴巴软件中,一旦您成功注册一个账号,系统就会为您分配一个独特的ID,这个ID将作为您在平台上的身份标识。但是对于许多用户来说,他们会想要查询自己的ID,但是却不知道该如何操作。那么本站小编带来下文中,就将为大家带来详细的攻略步骤介绍,希望能帮助到大家!阿里巴巴id在哪里看答案:【阿里巴巴】-【我的】。1、首先打开阿里巴巴软件,进入到首页中后我们需要点击右下角的【我的】;2、然后来到我的页面中后我们在页面的上方就可以看到【id】了;阿里巴巴id和淘宝一样吗阿里巴巴id和淘宝id不一样,但是二

C语言return的用法详解C语言return的用法详解Oct 07, 2023 am 10:58 AM

C语言return的用法有:1、对于返回值类型为void的函数,可以使用return语句来提前结束函数的执行;2、对于返回值类型不为void的函数,return语句的作用是将函数的执行结果返回给调用者;3、提前结束函数的执行,在函数内部,我们可以使用return语句来提前结束函数的执行,即使函数并没有返回值。

事件 ID 4660:已删除对象 [修复]事件 ID 4660:已删除对象 [修复]Jul 03, 2023 am 08:13 AM

我们的一些读者遇到了事件ID4660。他们通常不确定该怎么做,所以我们在本指南中解释。删除对象时通常会记录事件ID4660,因此我们还将探索一些实用的方法在您的计算机上修复它。什么是事件ID4660?事件ID4660与活动目录中的对象相关,将由以下任一因素触发:对象删除–每当从ActiveDirectory中删除对象时,都会记录事件ID为4660的安全事件。手动更改–当用户或管理员手动更改对象的权限时,可能会生成事件ID4660。更改权限设置、修改访问级别或添加或删除人员或组时,可能会发生这种情

腾讯视频id在哪里查看腾讯视频id在哪里查看Feb 24, 2024 pm 06:25 PM

腾讯视频id在哪里查看?腾讯视频APP中是有专属的id,但是多数的用户不知道如何查看腾讯视频id,接下来就是小编为用户带来的腾讯视频id查看方法图文教程,感兴趣的用户快来一起看看吧!腾讯视频使用教程腾讯视频id在哪里查看1、首先打开腾讯视频APP,主页面右下角【个人中心】进入到专区;2、之后进入到个人中心页面,选择【设置】功能;3、然后在设置页面,点击最下方【退出账号】;4、最后在下图所示的页面即可查看到专属的id号。

php中success方法怎么用php中success方法怎么用Mar 06, 2023 am 09:12 AM

php中success方法是用于展示一个成功信息,其使用语法是“Success('...','Http://www.xxx.com/Admin/User/Index');”,当我们没有写Url的时候,系统则会判断有无上一页,如果有系统,则会跳转至上一页,否则将不会进行跳转。

Java中return和finally语句的执行顺序是怎样的?Java中return和finally语句的执行顺序是怎样的?Apr 25, 2023 pm 07:55 PM

源码:publicclassReturnFinallyDemo{publicstaticvoidmain(String[]args){System.out.println(case1());}publicstaticintcase1(){intx;try{x=1;returnx;}finally{x=3;}}}#输出上述代码的输出可以简单地得出结论:return在finally之前执行,我们来看下字节码层面上发生了什么事情。下面截取case1方法的部分字节码,并且对照源码,将每个指令的含义注释在

See all articles

Hot AI Tools

Undresser.AI Undress

Undresser.AI Undress

AI-powered app for creating realistic nude photos

AI Clothes Remover

AI Clothes Remover

Online AI tool for removing clothes from photos.

Undress AI Tool

Undress AI Tool

Undress images for free

Clothoff.io

Clothoff.io

AI clothes remover

AI Hentai Generator

AI Hentai Generator

Generate AI Hentai for free.

Hot Tools

Zend Studio 13.0.1

Zend Studio 13.0.1

Powerful PHP integrated development environment

Dreamweaver CS6

Dreamweaver CS6

Visual web development tools

EditPlus Chinese cracked version

EditPlus Chinese cracked version

Small size, syntax highlighting, does not support code prompt function

ZendStudio 13.5.1 Mac

ZendStudio 13.5.1 Mac

Powerful PHP integrated development environment

SublimeText3 Linux new version

SublimeText3 Linux new version

SublimeText3 Linux latest version