zoukankan      html  css  js  c++  java
  • 方维购物分享系统采集淘宝天猫商品的多张图片

    方维购物分享系统默认会采集商品的一张主图,为了更好的展示,我需要采集商品的多张图片;

    修改/core/services/goods.service.php->collectGoods()

    设置要采集的字段,加上item_img;

    //设置采集的字段
    $req
    = new ItemsListGetRequest; $req->setFields("num_iid,detail_url,cid,delist_time,desc,item_img");

    处理返回的多图数据,插入数据表

    //add by wangtongphp QQ:1006440989 将多张图片写入表
    $item ['item_imgs'] = ( array ) $item ['item_imgs'];
    $taobao_goods_pic = array ();
    if ($item ['item_imgs'] ['@attributes'] ['list']) {
        $item_img = ( array ) $item ['item_imgs'] ['item_img'];
        //如果是一维数组
        if ($item_img ['url']) {
            $taobao_goods_pic ['keyid'] = $goods ['keyid'];
            $taobao_goods_pic ['url'] = addslashes ( $item_img ['url'] );
            $taobao_goods_pic ['position'] = ( int ) $item_img ['position'];
            FDB::insert ( 'taobao_goods_pic', $taobao_goods_pic, false, true );
        } //如果是二维数组
        else {
            foreach ( $item_img as $k => $v ) {
                $v = ( array ) $v;
                $taobao_goods_pic ['keyid'] = $goods ['keyid'];
                $taobao_goods_pic ['url'] = addslashes ( $v ['url'] );
                $taobao_goods_pic ['position'] = ( int ) $v ['position'];
                FDB::insert ( 'taobao_goods_pic', $taobao_goods_pic, false, true );
            }
        }
    }

     用taobao.items.list.get接口输出的多张图片数据测试

    //var_dump($item['item_imgs'])的结果
    array(2) {
      ["@attributes"]=>
      array(1) {
        ["list"]=>
        string(4) "true"
      }
      ["item_img"]=>
      object(SimpleXMLElement)#12 (3) {
        ["id"]=>
        string(1) "0"
        ["position"]=>
        string(1) "0"
        ["url"]=>
        string(96) "http://img02.taobaocdn.com/bao/uploaded/i2/17682019848077558/T1T80tXwRfXXXXXXXX_!!0-item_pic.jpg"
      }
    }
    array(2) {
      ["@attributes"]=>
      array(1) {
        ["list"]=>
        string(4) "true"
      }
      ["item_img"]=>
      array(3) {
        [0]=>
        object(SimpleXMLElement)#16 (3) {
          ["id"]=>
          string(1) "0"
          ["position"]=>
          string(1) "0"
          ["url"]=>
          string(72) "http://img03.taobaocdn.com/bao/uploaded/i3/T19FK.XcddXXafSdQ._111702.jpg"
        }
        [1]=>
        object(SimpleXMLElement)#17 (3) {
          ["id"]=>
          string(10) "5538138250"
          ["position"]=>
          string(1) "1"
          ["url"]=>
          string(87) "http://img04.taobaocdn.com/bao/uploaded/i4/387027922/T2xmnAXf0aXXXXXXXX_!!387027922.jpg"
        }
        [2]=>
        object(SimpleXMLElement)#18 (3) {
          ["id"]=>
          string(10) "5548397863"
          ["position"]=>
          string(1) "2"
          ["url"]=>
          string(87) "http://img04.taobaocdn.com/bao/uploaded/i4/387027922/T2YIPuXl0aXXXXXXXX_!!387027922.jpg"
        }
      }
    }
  • 相关阅读:
    Python 文件操作
    Python 操作 sqlite
    Python中的random模块
    Linux系统下的/etc/nsswitch.conf文件
    Python 列表/元组/字典总结
    快斗之翼:python2的print和python3的print()
    田小计划:图解Python深拷贝和浅拷贝
    Python 自省指南
    Python运算符优先级
    tc: 模拟网络异常的工具
  • 原文地址:https://www.cnblogs.com/wangtongphp/p/3026609.html
Copyright © 2011-2022 走看看