欧美bbbwbbbw肥妇,免费乱码人妻系列日韩,一级黄片

PHP抓取淘寶商品的用戶(hù)曬單評(píng)論+圖片+搜索商品列表實(shí)例

 更新時(shí)間:2016年04月14日 11:13:32   作者:國(guó)盛工作室  
下面是小編在前段時(shí)間做淘寶客引發(fā)的一些思考,有關(guān)PHP抓取淘寶商品的用戶(hù)曬單評(píng)論+圖片實(shí)例的方法,需要的朋友參考下吧

說(shuō)起來(lái)做這個(gè)功能還真是一時(shí)好奇。前段時(shí)間在做一個(gè)淘客網(wǎng)站的時(shí)候,想到是否能抓取到淘寶商品的買(mǎi)家秀呢?經(jīng)過(guò)一番折騰發(fā)現(xiàn),淘寶商品用戶(hù)評(píng)價(jià)信息是通過(guò)Ajax來(lái)調(diào)取的,通過(guò)嗅探網(wǎng)址發(fā)現(xiàn),評(píng)論數(shù)據(jù)的請(qǐng)求接口是:

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

其實(shí)上面很多參數(shù)也很容易理解,itemId是商品的ID,currentPage是當(dāng)前頁(yè),picture為1時(shí)顯示有圖的評(píng)價(jià),既然是抓取買(mǎi)家秀,那么picture參數(shù)一定要為1了。

如果你直接去訪(fǎng)問(wèn)上面的接口時(shí),會(huì)得到如下圖所示的請(qǐng)求結(jié)果:


看到請(qǐng)求結(jié)果是jsonp格式我就蛋碎了,我不知道如何去解析,但是換種思路,直接用PHP的正則去解析也未嘗不可嘛,通過(guò)嘗試,已經(jīng)正確的能夠解析到評(píng)論內(nèi)容和買(mǎi)家秀的圖片內(nèi)容,如圖:

效果不錯(cuò),代碼實(shí)現(xiàn)了評(píng)論內(nèi)容的抓取、買(mǎi)家秀圖片的抓取,代碼奉上:

<?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";
$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 "<p>".str_replace('","rateDate":"',' ',str_replace('","reply"','',str_replace('"rateContent":"','',$matchcomments_only[0])))."</p>";
$pattern3 = '/img.alicdn(.+?).jpg/is';
preg_match($pattern3, $match[0][$i], $matchpic_only);
echo '<img src="http://'.$matchpic_only[0].'" width=120>';
}
/*匹配一張圖片
$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 "<p>".$matchpic_only[0]."</p>";
}*/
/*匹配所有圖片
$pattern = '/"pics"(.+?)","position"/is';
preg_match_all($pattern, $texts, $matchpic);
for($i=0;$i<count($matchpic[0]);$i++){
$pics_str=str_replace('"pics":["http://','',str_replace('"],"picsSmall":"","position"','',$matchpic[0][$i]));
$arr = explode('","http://',$pics_str);
echo "<p>";
foreach($arr as $newstr){
echo '<img src=http://'.$newstr.' width=100 >';
}
echo "</p>";
}*/
?> 

下面給大家介紹PHP抓取淘寶搜索商品列表實(shí)例

<?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; 
//說(shuō)明:抓取網(wǎng)頁(yè)使用的是 Snoopyphp 框架 也可以直接使用file_get_contents函數(shù)獲取即可,
//var_dump($html);
preg_match_all('/<h3 class="summary">.*</a>/',$html,$result);
//preg_match_all('/<divsid="([a-z0-9_]+)">([^<>]+)</div>/',$html,$result);
var_dump($result);
echo "<br>";
/*
//循環(huán)讀取數(shù)組
foreach($result as $key1){
foreach($key1 as $key => $val){
echo $key.$val;
}
}
*/

以上所述是小編給大家介紹的PHP抓取淘寶商品的用戶(hù)曬單評(píng)論+圖片+搜索商品列表實(shí)例,希望對(duì)大家有所幫助!

相關(guān)文章

最新評(píng)論