Fork me on GitHub

Python爬取王者荣耀图片(安琪拉)

import requests
import os
root = "C://Users//-PC//Desktop//python//" 

try:
    for x in range(1,5):
        url = 'http://game.gtimg.cn/images/yxzj/img201606/skin/hero-info/142/142-bigskin-{0}{1}'.format(x,'.jpg')
        path = root + url.split("/")[-1]
        if not os.path.exists(root):
            os.mkdir(root)
        if not os.path.exists(path):
               r = requests.get(url)
               r.raise_for_status()
               with open(path,"wb") as f:
                   f.write(r.content)
                   print("爬取完成")
        else:
            print("文件已存在")
except Exception as e:
    print("爬取失败" + str(e))

 

posted @ 2018-11-07 22:30  都一样*  阅读(871)  评论(0编辑  收藏  举报