爬取王者荣耀壁纸

# -*-coding = utf-8 -*-
# @Time:2021/4/515:04
# @Author:seven
# @File:you.py
# @Software:PyCharm
import requests
import re
import os
findlink=re.compile(r'Fishow%2F(\d*)%2F(\d*)%5F(\d*)%5F(\d*)%5Fs')
url='https://apps.game.qq.com/cgi-bin/ams/module/ishow/V1.0/query/workList_inc.cgi?activityId=2735&sVerifyCode=ABCD&sDataType=JSON&iListNum=300&totalpage=0&page=0&iOrder=0&iSortNumClose=1&jsoncallback=jQuery17103435597512835047_1617606149156&iAMSActivityId=51991&_everyRead=true&iTypeId=2&iFlowId=267733&iActId=2735&iModuleId=2735&_=1617606149422'
html=requests.get(url)
list=re.findall(findlink,html.text)
w=[]
for i in list:
    print(i)
    a='http://shp.qpic.cn/ishow/'
    q=a+i[0]+'/'+i[1]+'_'+i[2]+'_'+i[3]+'_sProdImgNo_2.jpg/0'
    w.append(q)
w=set(w)
name='D:/王者'
if not os.path.exists(name):
    os.mkdir(name)  # 如果该目录不存在就创建它
os.chdir(name)      #定位到某文件夹
num=1
for url in w:
    if requests.get(url).text!="":
        with open(f'{num}.jpg','wb+') as fy:
            fy.write(requests.get(url).content)
            fy.close()
        print(f'爬取成功{num}')
        num+=1
    else:
        num=num

你可能感兴趣的:(python,爬虫,python,爬虫)