Home Backend Development PHP Tutorial PHP implements grabbing Taobao product price popularity source code

PHP implements grabbing Taobao product price popularity source code

Jul 29, 2016 am 09:04 AM
content data id return success

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></code>
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.

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

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 Article

R.E.P.O. Energy Crystals Explained and What They Do (Yellow Crystal)
2 weeks ago By 尊渡假赌尊渡假赌尊渡假赌
Repo: How To Revive Teammates
4 weeks ago By 尊渡假赌尊渡假赌尊渡假赌
Hello Kitty Island Adventure: How To Get Giant Seeds
3 weeks ago By 尊渡假赌尊渡假赌尊渡假赌

Hot Tools

Notepad++7.3.1

Notepad++7.3.1

Easy-to-use and free code editor

SublimeText3 Chinese version

SublimeText3 Chinese version

Chinese version, very easy to use

Zend Studio 13.0.1

Zend Studio 13.0.1

Powerful PHP integrated development environment

Dreamweaver CS6

Dreamweaver CS6

Visual web development tools

SublimeText3 Mac version

SublimeText3 Mac version

God-level code editing software (SublimeText3)

This Apple ID is not yet in use in the iTunes Store: Fix This Apple ID is not yet in use in the iTunes Store: Fix Jun 10, 2024 pm 05:42 PM

When logging into iTunesStore using AppleID, this error saying "This AppleID has not been used in iTunesStore" may be thrown on the screen. There are no error messages to worry about, you can fix them by following these solution sets. Fix 1 – Change Shipping Address The main reason why this prompt appears in iTunes Store is that you don’t have the correct address in your AppleID profile. Step 1 – First, open iPhone Settings on your iPhone. Step 2 – AppleID should be on top of all other settings. So, open it. Step 3 – Once there, open the “Payment & Shipping” option. Step 4 – Verify your access using Face ID. step

Fix event ID 55, 50, 98, 140 disk error in event viewer Fix event ID 55, 50, 98, 140 disk error in event viewer Mar 19, 2024 am 09:43 AM

If you find event ID 55, 50, 140 or 98 in the Event Viewer of Windows 11/10, or encounter an error that the disk file system structure is damaged and cannot be used, please follow the guide below to resolve the issue. What does Event 55, File system structure on disk corrupted and unusable mean? At session 55, the file system structure on the Ntfs disk is corrupted and unusable. Please run the chkMSK utility on the volume. When NTFS is unable to write data to the transaction log, an error with event ID 55 is triggered, which will cause NTFS to fail to complete the operation unable to write the transaction data. This error usually occurs when the file system is corrupted, possibly due to the presence of bad sectors on the disk or the file system's inadequacy of the disk subsystem.

Detailed explanation of the usage of return in C language Detailed explanation of the usage of return in C language Oct 07, 2023 am 10:58 AM

The usage of return in C language is: 1. For functions whose return value type is void, you can use the return statement to end the execution of the function early; 2. For functions whose return value type is not void, the function of the return statement is to end the execution of the function. The result is returned to the caller; 3. End the execution of the function early. Inside the function, we can use the return statement to end the execution of the function early, even if the function does not return a value.

Where can I find Alibaba ID? Where can I find Alibaba ID? Mar 08, 2024 pm 09:49 PM

In Alibaba software, once you successfully register an account, the system will assign you a unique ID, which will serve as your identity on the platform. But for many users, they want to query their ID, but don't know how to do it. Then the editor of this website will bring you detailed introduction to the strategy steps below. I hope it can help you! Where can I find the answer to Alibaba ID: [Alibaba]-[My]. 1. First open the Alibaba software. After entering the homepage, we need to click [My] in the lower right corner; 2. Then after coming to the My page, we can see [id] at the top of the page; Alibaba Is the ID the same as Taobao? Alibaba ID and Taobao ID are different, but the two

Where to check Tencent Video ID Where to check Tencent Video ID Feb 24, 2024 pm 06:25 PM

Where can I check the Tencent Video ID? There is an exclusive ID in the Tencent Video APP, but most users do not know how to check the Tencent Video ID. Next is the graphic tutorial on how to check the Tencent Video ID brought by the editor for users who are interested. Users come and take a look! Tencent Video Usage Tutorial Where to check Tencent Video ID 1. First open the Tencent Video APP and enter the special area through [Personal Center] in the lower right corner of the main page; 2. Then enter the Personal Center page and select the [Settings] function; 3. Then go to Settings page, click [Exit Account] at the bottom; 4. Finally, you can view the exclusive ID number on the page shown below.

Event ID 4660: Object deleted [Fix] Event ID 4660: Object deleted [Fix] Jul 03, 2023 am 08:13 AM

Some of our readers encountered event ID4660. They're often not sure what to do, so we explain it in this guide. Event ID 4660 is usually logged when an object is deleted, so we will also explore some practical ways to fix it on your computer. What is event ID4660? Event ID 4660 is related to objects in Active Directory and will be triggered by any of the following factors: Object Deletion – A security event with Event ID 4660 is logged whenever an object is deleted from Active Directory. Manual changes – Event ID 4660 may be generated when a user or administrator manually changes the permissions of an object. This can happen when changing permission settings, modifying access levels, or adding or removing people or groups

How to use success method in php How to use success method in php Mar 06, 2023 am 09:12 AM

The success method in php is used to display a success message. Its usage syntax is "Success('...','Http://www.xxx.com/Admin/User/Index');", when we do not write Url, the system will determine whether there is a previous page. If there is a system, it will jump to the previous page, otherwise it will not jump.

What is the execution order of return and finally statements in Java? What is the execution order of return and finally statements in Java? Apr 25, 2023 pm 07:55 PM

Source code: publicclassReturnFinallyDemo{publicstaticvoidmain(String[]args){System.out.println(case1());}publicstaticintcase1(){intx;try{x=1;returnx;}finally{x=3;}}}#Output The output of the above code can simply conclude: return is executed before finally. Let's take a look at what happens at the bytecode level. The following intercepts part of the bytecode of the case1 method, and compares the source code to annotate the meaning of each instruction in

See all articles