python爬取Clash Royale高清壁纸

版权声明:本文为博主原创文章,未经博主允许不得转载。 https://blog.csdn.net/Lingdongtianxia/article/details/85262763

部落冲突-皇室战争的卡牌人物设计的还是挺有水平的,走的简洁风格,而且设计非常统一,看起来就非常舒服,之前一直在找有关皇室战争的壁纸,现在找到一个国外的网站,里面大概有180多张高清壁纸,而且每一张壁纸都支持多分辨率下载,可以根据机型来选择分辨率,非常人性化。网址:www.clashroyalekingdom.com   ,国内网速不好,我要用无线网 才可以打开,中国移动的数据打不开,找个梯子才可以。

为了方便会Python的皇室战争玩家,我把代码贴在下面,代码一次运行可以下载单一分辨率的所有图片,如果有小伙伴不会python,可以在下边留言,我看情况给百度网盘链接。图片不多,没用多线程,凑合着用吧!

'''
Parameter c is image resolution
You can choose the resolution based on the device type
------------------
iPhone	640x960
	640x1136
	750x1334
	1080x1920
	1125x2436
Android	768x1280
	1080x1920
	1440x2560
	1440x2960
	2160x3840
Windows Phone
	480x800
	720x1280
	768x1280
	1080x1920
	1440x2560
Tablet	1920x1200
	2048x1536
	2224x1668
	2560x1600
	2732x2048
-------------------
'''
import urllib.request
from bs4 import BeautifulSoup

def htmlcode(a):
    page = urllib.request.urlopen(a)
    print("Had get Html code")
    return page.read()
def get_link(b):
    bs = BeautifulSoup(htmlcode(b),"html.parser")
    a = list(bs.find_all("a"))
    link = []
    for i in a:
        if "class" in str(i):
            link.append(str(i).split('"')[3])
    return link[:9]
def get_text(c):
    t = []
    text = []
    link = get_link(c)
    #print(link)
    for i in link:
        t.append(i.split('com/')[-1])
    for i in t:
        text.append(i[:-11].replace("-",''))
    return text
def download(address, file_name):
    try:
        urllib.request.urlretrieve(address,file_name)
        print(file_name+" OK")
        f.write(file_name+' OK\n')
    except:
        print("!!!Failed at "+address)
        f.write(address+'\n')

a = 'https://clashroyalekingdom.com/wallpaperdownload/'
b = '/?version='
c = '2732x2048'

download_address = 'https://clashroyalekingdom.com/wallpaper/page/{}/'

f = open("log.txt","a")
for w in range(1,21):
    print("Page "+str(w))
    for i in get_text(download_address.format(w)):
        download(a+i+b+c, i+'_'+c+'.jpg')
f.close()

猜你喜欢

转载自blog.csdn.net/Lingdongtianxia/article/details/85262763