Home >Backend Development >PHP Tutorial >Use PHP to capture user comments and pictures of Taobao products. PHP collects Taobao data. Taobao automatically delivers PHP. Xiaocao Taobao guest PHP.
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¤tPage=1&append=0&c/span>
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:
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:
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¤tPage=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 = '/"pics"(.+?)","reply"/is';preg_match_all($pattern, $texts, $match);for($i=0;$i<count($match[0]);$i++){$pattern2 = '/"rateContent":"(.+?)."reply"/is';preg_match($pattern2, $match[0][$i], $matchcomments_only);echo "".str_replace('","rateDate":"',' ',str_replace('","reply"','',str_replace('"rateContent":"','',$matchcomments_only[0])))."";$pattern3 = '/img.alicdn(.+?).jpg/is';preg_match($pattern3, $match[0][$i], $matchpic_only);echo '$matchpic_only[0].'" width="120" _src="http://'.$matchpic_only[0].'"/>'; }/*匹配一张图片 $pattern = '/"pics"(.+?)","position"/is'; preg_match_all($pattern, $texts, $matchpic); for($i=0;$i<count($matchpic[0]);$i++){ $pattern3 = '/img.alicdn(.+?).jpg/is'; preg_match($pattern3, $matchpic[0][$i], $matchpic_only); echo "".$matchpic_only[0].""; }*//*匹配所有图片 $pattern = '/"pics"(.+?)","position"/is'; preg_match_all($pattern, $texts, $matchpic); for($i=0;$i<count($matchpic[0]);$i++){ $pics_str=str_replace('"pics":["//','',str_replace('"],"picsSmall":"","position"','',$matchpic[0][$i])); $arr = explode('","//',$pics_str); echo ""; foreach($arr as $newstr){ echo ''; } echo ""; }*/?>
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.