Use PHP to capture user comments and pictures of Taobao products. PHP collects Taobao data. Taobao automatically delivers PHP. Xiaocao Taobao guest PHP.

不言
Release: 2023-02-28 21:50:01
Original
5470 people have browsed it

Why do you want to do this function? It's because when I was building a Taoke website some time ago, I thought about whether I could capture the buyer's show of Taobao products? After some tossing, I found that Taobao product user evaluation information is retrieved through Ajax. By sniffing the URL, I found that the request interface for comment data is:

https://rate.tmall.com/list_detail_rate.htm?itemId=524394294771&spuId=341564036&sellerId=100414600&order=3&currentPage=1&append=0&c/span>
Copy after login

In fact, many of the parameters above are also easy to understand. The itemId is The ID of the product, currentPage is the current page, and when picture is 1, reviews with pictures are displayed. Since the buyer's show is captured, the picture parameter must be 1.

If you directly access the above interface, you will get the request result as shown below:

Use PHP to capture user comments and pictures of Taobao products. PHP collects Taobao data. Taobao automatically delivers PHP. Xiaocao Taobao guest PHP.

I was shocked when I saw that the request result is in jsonp format. I don’t know how to parse it, but try another way Idea, it’s not a bad idea to directly use PHP’s regular parsing. After trying it, we can correctly parse the comment content and the picture content of the buyer’s show, as shown in the picture:

Use PHP to capture user comments and pictures of Taobao products. PHP collects Taobao data. Taobao automatically delivers PHP. Xiaocao Taobao guest PHP.

The effect is good, the code realizes the comment content To capture and capture buyer show pictures, here is the code:

<?php$url = "https://rate.tmall.com/list_detail_rate.htm?itemId=524394294771&spuId=341564036&sellerId=100414600&order=3&currentPage=1&append=0&c>;$ch2 = curl_init();
curl_setopt($ch2, CURLOPT_URL, $url);
curl_setopt($ch2, CURLOPT_FOLLOWLOCATION, TRUE);
curl_setopt($ch2, CURLOPT_SSL_VERIFYHOST, FALSE);
curl_setopt($ch2, CURLOPT_SSL_VERIFYPEER, false);
curl_setopt($ch2, CURLOPT_RETURNTRANSFER, TRUE);$texts = curl_exec($ch2);
curl_close($ch2);//echo $texts;$pattern = &#39;/"pics"(.+?)","reply"/is&#39;;preg_match_all($pattern, $texts, $match);for($i=0;$i<count($match[0]);$i++){$pattern2 = &#39;/"rateContent":"(.+?)."reply"/is&#39;;preg_match($pattern2, $match[0][$i], $matchcomments_only);echo "".str_replace(&#39;","rateDate":"&#39;,&#39; &#39;,str_replace(&#39;","reply"&#39;,&#39;&#39;,str_replace(&#39;"rateContent":"&#39;,&#39;&#39;,$matchcomments_only[0])))."";$pattern3 = &#39;/img.alicdn(.+?).jpg/is&#39;;preg_match($pattern3, $match[0][$i], $matchpic_only);echo &#39;$matchpic_only[0].&#39;" width="120" _src="http://&#39;.$matchpic_only[0].&#39;"/>&#39;;
}/*匹配一张图片
$pattern = &#39;/"pics"(.+?)","position"/is&#39;;
preg_match_all($pattern, $texts, $matchpic);
for($i=0;$i<count($matchpic[0]);$i++){
    $pattern3 = &#39;/img.alicdn(.+?).jpg/is&#39;;
    preg_match($pattern3, $matchpic[0][$i], $matchpic_only);
    echo "".$matchpic_only[0]."";
}*//*匹配所有图片
$pattern = &#39;/"pics"(.+?)","position"/is&#39;;
preg_match_all($pattern, $texts, $matchpic);
for($i=0;$i<count($matchpic[0]);$i++){
    $pics_str=str_replace(&#39;"pics":["//&#39;,&#39;&#39;,str_replace(&#39;"],"picsSmall":"","position"&#39;,&#39;&#39;,$matchpic[0][$i]));
    $arr = explode(&#39;","//&#39;,$pics_str);
    echo "";
    foreach($arr as $newstr){
        echo &#39;&#39;;
    }
    echo "";
}*/?>
Copy after login

Is there a good way to parse the jsonp format? Please help me~~~

The above introduces examples of using PHP to capture users’ comments and pictures of Taobao products, including PHP and Taobao merchant content. I hope it will be helpful to friends who are interested in PHP tutorials.


Related labels:
php
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