• python 图片抓取


    1、图片地址为下载地址访问图片地址可直接下载的

      #!/usr/bin/env python
      # -*- coding: utf-8 -*-
      import urllib2
      import json
      import requests
      import os
      import sys
      from time import sleep
      reload(sys)
      sys.setdefaultencoding("utf-8")
      def uploadreColorImg():
      file_recolorJson = "/home/siyin/Downloads/LibraryMD5.json"
      recolor_url = "basicurl"
      savePath = "/home/siyin/recolor0621/"
      with open(file_recolorJson) as f:
      j = json.loads(f.read())
      books = j.get("Books")
      for item in books:
      count = 0
      category = item
      os.mkdir(savePath+category,0775)
      os.mkdir(savePath + category+"/c", 0775)
      imglist = books.get(item)
      for elem in imglist:
      contents = imglist.get(elem).get("Contents")
      for ele in contents :
      count = count + 1
      art = contents.get("Art")
      artUrl = recolor_url + art
      try:
      print artUrl
      r_art = requests.get(artUrl)
      print r_art.status_code
      if r_art.status_code == 200:
      with open(savePath+category+"/"+art+".pdf","wb") as output:
      for chunk in r_art:
      output.write(chunk)
      except:
      sleep(5)
      continue
      finally:
      output.close()
      print count

      if __name__ == "__main__":

      uploadreColorImg()

    2、url是图片链接

    #!/usr/bin/env python
    # -*- coding: utf-8 -*-

    import json
    import requests
    import os
    import sys
    import time
    import urllib
    reload(sys)
    sys.setdefaultencoding("utf-8")

    def getAndSaveImg(urlParam,save_absPath):

    urllib.urlretrieve(urlParam,save_absPath)

    def uploadColorImg():

    file_json = "/home/siyin/colorfy/colorfy_json.json"
    color_url = "http://cdn.colorfy.fungames-forfree.com/v2/android/galleries/images/"
    savePath = "/home/siyin/colorfy/"
    with open(file_json) as f:
    j = json.loads(f.read())
    galleries = j.get("galleries")
    for gallery in galleries:
    galleryId = gallery.get("id")
    os.mkdir(savePath+galleryId,0775)
    volumes = gallery.get("volumes")
    if volumes is not None:
    for volume in volumes:
    volumeId = volume.get("id")
    paintings = volume.get("paintings")
    for painting in paintings:
    img_path = painting.get("img_path")
    img_url = color_url + img_path + '.png'
    save_absPath = savePath + galleryId + "/" + img_path + '.png'
    try:
    r_img = requests.get(img_url)
    if r_img.status_code == 200:
    getAndSaveImg(img_url,save_absPath)
    else:
    print "error"
    except:
    time.sleep(5)
    continue
    print img_path

    if __name__ == "__main__":
    uploadColorImg()

  • 相关阅读:
    Network Simulator for P4(NSP4) src内容介绍
    解决 E: Unable to correct problems, you have held broken packages. 问题
    【旧版本】Ubuntu 14.04 下 P416编译器 p4c的安装
    Ubuntu 14.04 更新gcc版本至4.9.2
    Ubuntu 14.04 下 安装Protocol Buffers
    Ubuntu 14.04 删除软件附加依赖
    解决Floodlight界面无法显示问题
    OpenVirteX 创建简易虚拟网络
    2017年P4中国峰会北京站 会议小结
    406. Queue Reconstruction by Height
  • 原文地址:https://www.cnblogs.com/sy-liu/p/7058174.html
Copyright © 2020-2023  润新知