A&F官网的衣服图片分成三个种类,通过在基础URL的后面添加查询字符串来区分图片种类
1 2 3 4 5 6 7 8 |
//第一种图片格式,带背景的小图片,大小226×226 http://anf.scene7.com/is/image/anf/anf_77827_01_prod1?$category-anf$ //第二种图片格式,带背景的大图片,大小1200×1200 http://anf.scene7.com/is/image/anf/anf_77827_01_prod1?$productMagnify-anf$ //第三种图片格式,透明背景的大图片,大小1000×1000 http://anf.scene7.com/is/image/anf/anf_77827_01_prod1 |
官网的图片是采用js延迟载入的,图片地址保存在data-src属性中
1 2 3 4 5 |
//原始的图片dom <img id="prod-img-2327571" class="prod-img pointer lazyload" data-s7-preset="category-anf" data-src="//anf.scene7.com/is/image/anf/anf_77827_01_prod1?$category-anf$" alt="Mens Vintage Graphic Tee"> //加载完毕后的图片dom <img id="prod-img-2327571" class="prod-img pointer imageLoadFix" data-s7-preset="category-anf" data-src="//anf.scene7.com/is/image/anf/anf_77827_01_prod1?$category-anf$" alt="Mens Vintage Graphic Tee" src="//anf.scene7.com/is/image/anf/anf_77827_01_prod1?$category-anf$" style="display: block;"> |
在每个单品的a中保存有商品的ID和分类ID。
1 |
<a href="/shop/us/mens-full-zip-hoodies-and-sweatshirts/upper-hudson-hoodie-2262574" data-productid="2262574" data-categoryid="87655">Upper Hudson Hoodie</a> |
PHP实现如下
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 |
<head></head> <body> <form name="url" method="get" action=""> <label for="url"></label> <input type="text" name="url" id="url" size="150"> <input type="submit" value="Submit"> </form> <?php /** * Created by PhpStorm. * User: Jason * Date: 14-3-8 * Time: 下午11:03 */ include_once('C:\xampp\htdocs\af-tools\Add-ons\simplehtmldom\simple_html_dom.php'); if(!empty($_GET['url'])) $url = $_GET["url"]; else $url = "http://www.abercrombie.com/shop/us/mens-hoodies-and-sweatshirts"; $html = file_get_html($url); if($html->find('.product')) $items = $html->find('.product'); $items_count = count($items); echo 'items-count : '.$items_count ."<br>"; for ($i=1; $i<=$items_count; $i++){ $img_src = $items[($i-1)]->find('.prod-img',0)->getAttribute('data-src'); $item_name = $items[($i-1)]->find('.name',0)->plaintext; $item_price_now = $items[($i-1)]->find('.offer-price',0)->plaintext; $item_product_id = $items[($i-1)]->find('.name a',0)->getAttribute('data-productid'); $item_category_id = $items[($i-1)]->find('.name a',0)->getAttribute('data-categoryid'); echo $i .'.'; echo 'img-src : http:'.$img_src ."<br>"; echo 'items-name : '.$item_name ."<br>"; echo 'items-price-now : '.$item_price_now ."<br>"; echo 'items-product-id : '.$item_product_id ."<br>"; echo 'items-category-id : '.$item_category_id ."<br>"; } |
There are no comments yet