抓取淘宝数据

<?php   
$url = "http://item.taobao.com/item.htm?spm=a2106.m874.1000384.165.IA5bMW&id=36415610506&scm=1029.newlist-0.1.50102538&ppath=&sku=&ug="; 
$ch = curl_init(); 
$timeout = 5; 
curl_setopt($ch, CURLOPT_URL, $url); 
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); 
curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, $timeout); 
//在需要用户检测的网页里需要增加下面两行 
//curl_setopt($ch, CURLOPT_HTTPAUTH, CURLAUTH_ANY); 
//curl_setopt($ch, CURLOPT_USERPWD, US_NAME.":".US_PWD); 
$contents = curl_exec($ch); 
curl_close($ch); 
if(preg_match('/<h3 class="tb-item-title">.*<\/h3>/',$contents, $matches)){
    print "衣服名称:". $matches[0];
} else {
    print "A match was not found.";
}
if(preg_match('/<img id="J_ImgBooth"(.*)>/',$contents, $matches)){
    $get=$matches[1];
    $get2=explode(" ",$get);
    echo "图片:<img src=".substr($get2[1],9)."/>";
} else {
    print "2A match was not found.";
}
if(preg_match('/<em class="tb-rmb-num">(.*?)<\/em>/',$contents, $matches)){
echo "3e".$matches[1];
}
//<strong class="tb-rmb-num"><em class="tb-rmb">¥</em>45.00</strong>
if(preg_match('/<strong class="tb-rmb-num"><em class="tb-rmb">¥<\/em>(.*)<\/strong>/s',$contents, $matches)){
echo "衣服价格:".var_dump($matches);
}
if(preg_match('/<img data-src=\"(.+?)\".*?>/',$contents, $matches)){
var_dump($matches);
}


你可能感兴趣的:(web开发,抓取,淘宝数据)