PHP grab the user of Taobao products comments + photos + Search Items List Instance _php instance

Source: Internet
Author: User
Tags comments

It's a curious thing to say about this function. Some time ago in doing a Amoy site, think of whether you can crawl to Taobao merchandise buyers show it? After some toss and find, Taobao Commodity user evaluation information is through Ajax to transfer, through the sniffer web site found that the comment data request interface is:

https://rate.tmall.com/list_detail_rate.htm?itemId=524394294771&spuId=341564036&sellerId=100414600 &order=3&currentpage=1&append=0&content=1&tagid=&posi=&picture=1&callback= jsonp2339

In fact, many of the parameters are also very easy to understand, Itemid is the product of the Id,currentpage is the current page, the picture for 1 o'clock show a map of the evaluation, since it is a grab buyer show, then pictures parameters must be 1.

If you go directly to the above interface, you will get the result of the request as shown in the following figure:


See the request result is JSONP format I will be broken eggs, I do not know how to resolve, but to change the way of thinking, directly with the PHP to parse also may not be, through the attempt, has been able to parse the content of the comments and buyers show the picture content, as shown:

The effect is good, the code to achieve the content of the crawl, buyers show the image of the capture, code to serve:

<?php $url = "Https://rate.tmall.com/list_detail_rate.htm?itemId=524394294771&spuId=341564036&sellerId =100414600&order=3&currentpage=1&append=0&content=1&tagid=&posi=&picture=1&
callback=jsonp2339 ";
$ch 2 = Curl_init ();
curl_setopt ($ch 2, Curlopt_url, $url);
curl_setopt ($ch 2, curlopt_followlocation, TRUE);
curl_setopt ($ch 2, Curlopt_ssl_verifyhost, FALSE);
curl_setopt ($ch 2, Curlopt_ssl_verifypeer, false);
curl_setopt ($ch 2, Curlopt_returntransfer, TRUE);
$texts = Curl_exec ($ch 2);
Curl_close ($ch 2);
Echo $texts;
$pattern = '/' pics ' (. +?) "," Reply "/is";
Preg_match_all ($pattern, $texts, $match); For ($i =0 $i <count ($match [0]); $i + +) {$pattern 2 = '/' ratecontent ': ' (. +?). "
Reply "/is '";
Preg_match ($pattern 2, $match [0][$i], $matchcomments _only); echo "<p>". Str_replace (' "," ratedate ":" ', ", Str_replace ('", "Reply", ",", Str_replace (' ratecontent '): "', ', $ Matchcomments_only[0])). "
</p> "; $pattern 3 = '/img.alicdn (. +?).
Jpg/is '; Preg_match ($pattern 3, $MATCh[0][$i], $matchpic _only);
Echo '  ';
/* match a picture $pattern = '/' pics ' (. +?) "," position "/is";
Preg_match_all ($pattern, $texts, $matchpic); For ($i =0 $i <count ($matchpic [0]), $i + +) {$pattern 3 = '/img.alicdn (. +?).
Jpg/is ';
Preg_match ($pattern 3, $matchpic [0][$i], $matchpic _only); echo "<p>" $matchpic _only[0]. "
</p> ";
}*//* matches all pictures $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 "<p>";
foreach ($arr as $newstr) {echo '  ';} echo ' </p> ';  }*/?>

below to introduce you to the PHP crawl Taobao search Merchandise List Instances

<?php
Header ("CONTENT-TYPE:TEXT/HTML;CHARSET=GBK");
Include "Snoopy.class.php"; 
$snoopy = new Snoopy; 
$snoopy->fetch ("Http://s.taobao.com/search?spm=a230r.1.8.7.2NN4M7&q=%C7%EF%B6%AC%B4%F3%D2%C2&source =tbsy&refpid=420461_1006&discount_index=1&newpre=null&p4p_str=fp_midtop%3d0%26firstpage_ Pushleft%3d0&style=list&s=0#j_filter "); 
$html = $snoopy->results; 
Description: Crawl Web page using the snoopyphp framework can also be directly used to obtain file_get_contents function,
//var_dump ($html);
Preg_match_all ('/

The above is a small set to introduce you to the PHP crawl Taobao products users comments + photos + Search Products List examples, I hope to help you!

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.