python 爬取王者荣耀全套皮肤壁纸

python

1.获取英雄列表

 打开官网英雄列表页面 https://pvp.qq.com/web201605/herolist.shtml

可以看到所有英雄都在 herolist.json

里面的内容是这样的 

[{

"ename": 105,

"cname": "廉颇",

"title": "正义爆轰",

"new_type": 0,

"hero_type": 3,

"skin_name": "正义爆轰|地狱岩魂"

}, {

"ename": 106,

"cname": "小乔",

"title": "恋之微风",

"pay_type": 10,

"new_type": 0,

"hero_type": 2,

"skin_name": "恋之微风|万圣前夜|天鹅之梦|纯白花嫁|缤纷独角兽"

}, {

"ename": 107,

"cname": "赵云",

"title": "苍天翔龙",

"pay_type": 10,

"new_type": 0,

"hero_type": 1,

"hero_type2": 4,

"skin_name": "苍天翔龙|忍●炎影|未来纪元|皇家上将|嘻哈天王|白执事|引擎之心"

}, {

"ename": 108,

"cname": "墨子",

"title": "和平守望",

"new_type": 0,

"hero_type": 2,

"hero_type2": 1,

"skin_name": "和平守望|金属风暴|龙骑士|进击墨子号"

}, {

"ename": 109,

"cname": "妲己",

"title": "魅力之狐",

"pay_type": 11,

"new_type": 0,

"hero_type": 2,

"skin_name": "魅惑之狐|女仆咖啡|魅力维加斯|仙境爱丽丝|少女阿狸|热情桑巴"

}, {

"ename": 110,

"cname": "嬴政",

"title": "王者独尊",

"new_type": 0,

"hero_type": 2,

"skin_name": "王者独尊|摇滚巨星|暗夜贵公子|优雅恋人|白昼王子"

}, {

"ename": 111,

"cname": "孙尚香",

"title": "千金重弩",

"new_type": 0,

"hero_type": 5,

"skin_name": "千金重弩|火炮千金|水果甜心|蔷薇恋人|杀手不太冷|末日机甲|沉稳之力"

}, {

"ename": 112,

"cname": "鲁班七号",

"title": "机关造物",

"new_type": 0,

"hero_type": 5,

"skin_name": "机关造物|木偶奇遇记|福禄兄弟|电玩小子|星空梦想"

}, {

"ename": 113,

"cname": "庄周",

"title": "逍遥梦幻",

"new_type": 0,

"hero_type": 6,

"hero_type2": 3,

"skin_name": "逍遥幻梦|鲤鱼之梦|蜃楼王|云端筑梦师"

}, {

"ename": 114,

"cname": "刘禅",

"title": "暴走机关",

"new_type": 0,

"hero_type": 6,

"hero_type2": 3,

"skin_name": "暴走机关|英喵野望|绅士熊喵|天才门将"

}, {

"ename": 115,

"cname": "高渐离",

"title": "叛逆吟游",

"new_type": 0,

"hero_type": 2,

"skin_name": "叛逆吟游|金属狂潮|死亡摇滚"

}, {

"ename": 116,

"cname": "阿轲",

"title": "信念之刃",

"new_type": 0,

"hero_type": 4,

"skin_name": "信念之刃|爱心护理|暗夜猫娘|致命风华|节奏热浪"

}, {

"ename": 117,

"cname": "钟无艳",

"title": "野蛮之锤",

"new_type": 0,

"hero_type": 1,

"hero_type2": 3,

"skin_name": "野蛮之锤|生化警戒|王者之锤|海滩丽影"

}, {

"ename": 118,

"cname": "孙膑",

"title": "逆流之时",

"new_type": 0,

"hero_type": 6,

"hero_type2": 2,

"skin_name": "逆流之时|未来旅行|天使之翼|妖精王"

}, {

"ename": 119,

"cname": "扁鹊",

"title": "善恶怪医",

"new_type": 0,

"hero_type": 2,

"skin_name": "善恶怪医|救世之瞳|化身博士|炼金王"

}, {

"ename": 120,

"cname": "白起",

"title": "最终兵器",

"new_type": 0,

"hero_type": 3,

"skin_name": "最终兵器|白色死神|狰|星夜王子"

}, {

"ename": 121,

"cname": "芈月",

"title": "永恒之月",

"new_type": 0,

"hero_type": 2,

"hero_type2": 3,

"skin_name": "永恒之月|红桃皇后|大秦宣太后|重明"

}, {

"ename": 123,

"cname": "吕布",

"title": "无双之魔",

"new_type": 0,

"hero_type": 1,

"hero_type2": 3,

"skin_name": "无双之魔|圣诞狂欢|天魔缭乱|末日机甲|猎兽之王"

}, {

"ename": 124,

"cname": "周瑜",

"title": "铁血都督",

"new_type": 0,

"hero_type": 2,

"skin_name": "铁血都督|海军大将|真爱至上"

}, {

"ename": 126,

"cname": "夏侯惇",

"title": "不羁之风",

"pay_type": 10,

"new_type": 0,

"hero_type": 3,

"hero_type2": 1,

"skin_name": "不羁之风|战争骑士|乘风破浪|无限飓风号"

}, {

"ename": 127,

"cname": "甄姬",

"title": "洛神降临",

"new_type": 0,

"hero_type": 2,

"skin_name": "洛神降临|冰雪圆舞曲|花好人间|游园惊梦"

}, {

"ename": 128,

"cname": "曹操",

"title": "鲜血枭雄",

"pay_type": 10,

"new_type": 0,

"hero_type": 1,

"skin_name": "鲜血枭雄|超能战警|幽灵船长|死神来了|烛龙"

}, {

"ename": 129,

"cname": "典韦",

"title": "狂战士",

"new_type": 0,

"hero_type": 1,

"skin_name": "狂战士|黄金武士|穷奇"

}, {

"ename": 130,

"cname": "宫本武藏",

"title": "剑圣",

"new_type": 0,

"hero_type": 1,

"skin_name": "剑圣|鬼剑武藏|未来纪元|万象初新|地狱之眼|霸王丸"

}, {

"ename": 131,

"cname": "李白",

"title": "青莲剑仙",

"new_type": 0,

"hero_type": 4,

"skin_name": "青莲剑仙|范海辛|千年之狐|凤求凰|敏锐之力"

}, {

"ename": 132,

"cname": "马可波罗",

"title": "远游之枪",

"pay_type": 10,

"new_type": 0,

"hero_type": 5,

"skin_name": "远游之枪|激情绿茵|逐梦之星"

}, {

"ename": 133,

"cname": "狄仁杰",

"title": "断案大师",

"pay_type": 11,

"new_type": 0,

"hero_type": 5,

"skin_name": "断案大师|锦衣卫|魔术师|超时空战士|阴阳师"

}, {

"ename": 134,

"cname": "达摩",

"title": "拳僧",

"new_type": 0,

"hero_type": 1,

"hero_type2": 3,

"skin_name": "拳僧|大发明家|拳王"

}, {

"ename": 135,

"cname": "项羽",

"title": "霸王",

"new_type": 0,

"hero_type": 3,

"skin_name": "霸王|帝国元帅|苍穹之光|海滩派对|职棒王牌|霸王别姬|科学大爆炸"

}, {

"ename": 136,

"cname": "武则天",

"title": "女帝",

"new_type": 0,

"hero_type": 2,

"skin_name": "女帝|东方不败|海洋之心"

}, {

"ename": 139,

"cname": "老夫子",

"title": "万古长明",

"new_type": 0,

"hero_type": 1,

"skin_name": "万古长明|潮流仙人|圣诞老人|功夫老勺"

}, {

"ename": 140,

"cname": "关羽",

"title": "一骑当千",

"new_type": 0,

"hero_type": 1,

"skin_name": "一骑当千|天启骑士|冰锋战神|龙腾万里"

}, {

"ename": 141,

"cname": "貂蝉",

"title": "绝世舞姬",

"new_type": 0,

"hero_type": 2,

"hero_type2": 4,

"skin_name": "绝世舞姬|异域舞娘|圣诞恋歌|逐梦之音|仲夏夜之梦"

}, {

"ename": 142,

"cname": "安琪拉",

"title": "暗夜萝莉",

"new_type": 0,

"hero_type": 2,

"skin_name": "暗夜萝莉|玩偶对对碰|魔法小厨娘|心灵骇客|如懿"

}, {

"ename": 144,

"cname": "程咬金",

"title": "热烈之斧",

"new_type": 0,

"hero_type": 3,

"hero_type2": 1,

"skin_name": "热烈之斧|爱与正义|星际陆战队|华尔街大亨|功夫厨神"

}, {

"ename": 146,

"cname": "露娜",

"title": "月光之女",

"new_type": 0,

"hero_type": 1,

"hero_type2": 2,

"skin_name": "月光之女|哥特玫瑰|绯红之刃|紫霞仙子|一生所爱"

}, {

"ename": 148,

"cname": "姜子牙",

"title": "太古魔导",

"new_type": 0,

"hero_type": 2,

"skin_name": "太古魔导|时尚教父"

}, {

"ename": 149,

"cname": "刘邦",

"title": "双面君主",

"new_type": 0,

"hero_type": 3,

"skin_name": "双面君主|圣殿之光|德古拉伯爵"

}, {

"ename": 150,

"cname": "韩信",

"title": "国士无双",

"new_type": 0,

"hero_type": 4,

"skin_name": "国士无双|街头霸王|教廷特使|白龙吟|逐梦之影"

}, {

"ename": 152,

"cname": "王昭君",

"title": "冰雪之华",

"new_type": 0,

"hero_type": 2,

"skin_name": "冰雪之华|精灵公主|偶像歌手|凤凰于飞|幻想奇妙夜"

}, {

"ename": 153,

"cname": "兰陵王",

"title": "暗影刀锋",

"new_type": 0,

"hero_type": 4,

"skin_name": "暗影刀锋|隐刃|暗隐猎兽者"

}, {

"ename": 154,

"cname": "花木兰",

"title": "传说之刃",

"new_type": 0,

"hero_type": 1,

"hero_type2": 4,

"skin_name": "传说之刃|剑舞者|兔女郎|水晶猎龙者|青春决赛季|冠军飞将|瑞麟志"

}, {

"ename": 156,

"cname": "张良",

"title": "言灵之书",

"new_type": 0,

"hero_type": 2,

"skin_name": "言灵之书|天堂福音|一千零一夜|幽兰居士"

}, {

"ename": 157,

"cname": "不知火舞",

"title": "明媚烈焰",

"new_type": 0,

"hero_type": 2,

"hero_type2": 4,

"skin_name": "明媚烈焰"

}, {

"ename": 162,

"cname": "娜可露露",

"title": "鹰之守护",

"new_type": 0,

"hero_type": 4,

"skin_name": "鹰之守护"

}, {

"ename": 163,

"cname": "橘右京",

"title": "神梦一刀",

"new_type": 0,

"hero_type": 4,

"hero_type2": 1,

"skin_name": "神梦一刀"

}, {

"ename": 166,

"cname": "亚瑟",

"title": "圣骑之力",

"pay_type": 11,

"new_type": 0,

"hero_type": 1,

"hero_type2": 3,

"skin_name": "圣骑之力|死亡骑士|狮心王|心灵战警"

}, {

"ename": 167,

"cname": "孙悟空",

"title": "齐天大圣",

"new_type": 0,

"hero_type": 4,

"hero_type2": 1,

"skin_name": "齐天大圣|地狱火|西部大镖客|美猴王|至尊宝|全息碎影|大圣娶亲"

}, {

"ename": 168,

"cname": "牛魔",

"title": "精英酋长",

"new_type": 0,

"hero_type": 6,

"hero_type2": 3,

"skin_name": "精英酋长|西部大镖客|制霸全明星"

}, {

"ename": 169,

"cname": "后羿",

"title": "半神之弓",

"new_type": 0,

"hero_type": 5,

"skin_name": "半神之弓|精灵王|阿尔法小队|辉光之辰|黄金射手座"

}, {

"ename": 170,

"cname": "刘备",

"title": "仁德义枪",

"new_type": 0,

"hero_type": 1,

"skin_name": "仁德义枪|万事如意|纽约教父|汉昭烈帝"

}, {

"ename": 171,

"cname": "张飞",

"title": "禁血狂兽",

"pay_type": 10,

"new_type": 0,

"hero_type": 3,

"hero_type2": 6,

"skin_name": "禁血狂兽|五福同心|乱世虎臣"

}, {

"ename": 173,

"cname": "李元芳",

"title": "王都密探",

"new_type": 0,

"hero_type": 5,

"skin_name": "王都密探|特种部队|黑猫爱糖果|逐浪之夏"

}, {

"ename": 174,

"cname": "虞姬",

"title": "森之风灵",

"new_type": 0,

"hero_type": 5,

"skin_name": "森之风灵|加勒比小姐|霸王别姬|凯尔特女王"

}, {

"ename": 175,

"cname": "钟馗",

"title": "虚灵城判",

"pay_type": 10,

"new_type": 0,

"hero_type": 6,

"hero_type2": 2,

"skin_name": "虚灵城判|地府判官"

}, {

"ename": 177,

"cname": "成吉思汗",

"title": "苍狼末裔",

"new_type": 0,

"hero_type": 5,

"skin_name": "苍狼末裔|维京掠夺者"

}, {

"ename": 178,

"cname": "杨戬",

"title": "根源之目",

"new_type": 0,

"hero_type": 1,

"skin_name": "根源之目|埃及法老|永曜之星"

}, {

"ename": 183,

"cname": "雅典娜",

"title": "圣域余晖",

"new_type": 0,

"hero_type": 1,

"skin_name": "圣域余晖|战争女神|冰冠公主|神奇女侠"

}, {

"ename": 184,

"cname": "蔡文姬",

"title": "天籁弦音",

"new_type": 0,

"hero_type": 6,

"skin_name": "天籁弦音|蔷薇王座|舞动绿茵|奇迹圣诞"

}, {

"ename": 186,

"cname": "太乙真人",

"title": "炼金大师",

"new_type": 0,

"hero_type": 6,

"hero_type2": 3,

"skin_name": "炼金大师|圆桌骑士|饕餮|华丽摇滚"

}, {

"ename": 180,

"cname": "哪吒",

"title": "桀骜炎枪",

"new_type": 0,

"hero_type": 1,

"skin_name": "桀骜炎枪|三太子|逐梦之翼"

}, {

"ename": 190,

"cname": "诸葛亮",

"title": "绝代智谋",

"new_type": 0,

"hero_type": 2,

"skin_name": "绝代智谋|星航指挥官|黄金分割率|武陵仙君|掌控之力"

}, {

"ename": 192,

"cname": "黄忠",

"title": "燃魂重炮",

"new_type": 0,

"hero_type": 5,

"skin_name": "燃魂重炮|芝加哥教父"

}, {

"ename": 191,

"cname": "大乔",

"title": "沧海之曜",

"new_type": 0,

"hero_type": 6,

"skin_name": "沧海之曜|伊势巫女|守护之力|猫狗日记"

}, {

"ename": 187,

"cname": "东皇太一",

"title": "噬灭日蚀",

"new_type": 0,

"hero_type": 6,

"hero_type2": 3,

"skin_name": "噬灭日蚀|东海龙王|逐梦之光"

}, {

"ename": 182,

"cname": "干将莫邪",

"title": "淬命双剑",

"new_type": 0,

"hero_type": 2,

"skin_name": "淬命双剑|第七人偶|冰霜恋舞曲"

}, {

"ename": 189,

"cname": "鬼谷子",

"title": "万物有灵",

"new_type": 0,

"hero_type": 6,

"skin_name": "万物有灵|阿摩司公爵|幻乐之宴"

}, {

"ename": 193,

"cname": "铠",

"title": "破灭刃锋",

"new_type": 0,

"hero_type": 1,

"hero_type2": 3,

"skin_name": "破灭刃锋|龙域领主|曙光守护者|青龙志"

}, {

"ename": 196,

"cname": "百里守约",

"title": "静谧之眼",

"new_type": 0,

"hero_type": 5,

"hero_type2": 4,

"skin_name": "静谧之眼|绝影神枪|特工魅影|朱雀志"

}, {

"ename": 195,

"cname": "百里玄策",

"title": "嚣狂之镰",

"new_type": 0,

"hero_type": 4,

"skin_name": "嚣狂之镰|威尼斯狂欢|白虎志"

}, {

"ename": 194,

"cname": "苏烈",

"title": "不屈铁壁",

"new_type": 0,

"hero_type": 3,

"hero_type2": 1,

"skin_name": "不屈铁壁|爱与和平|坚韧之力|玄武志"

}, {

"ename": 198,

"cname": "梦奇",

"title": "入梦之灵",

"new_type": 0,

"hero_type": 1,

"hero_type2": 3,

"skin_name": "入梦之灵|美梦成真|胖达荣荣"

}, {

"ename": 179,

"cname": "女娲",

"title": "至高创世",

"new_type": 0,

"hero_type": 2,

"skin_name": "至高创世|尼罗河女神"

}, {

"ename": 501,

"cname": "明世隐",

"title": "灵魂劫卜",

"new_type": 0,

"hero_type": 6,

"skin_name": "灵魂劫卜|占星术士|虹云星官"

}, {

"ename": 199,

"cname": "公孙离",

"title": "幻舞玲珑",

"new_type": 0,

"hero_type": 5,

"skin_name": "幻舞玲珑|花间舞|蜜橘之夏"

}, {

"ename": 176,

"cname": "杨玉环",

"title": "霓裳风华",

"new_type": 0,

"hero_type": 2,

"skin_name": "风华霓裳|霓裳曲|遇见飞天"

}, {

"ename": 502,

"cname": "裴擒虎",

"title": "六合虎拳",

"new_type": 0,

"hero_type": 4,

"hero_type2": 1,

"skin_name": "六合虎拳|街头霸王|梅西"

}, {

"ename": 197,

"cname": "弈星",

"title": "天元之弈",

"new_type": 0,

"hero_type": 2,

"skin_name": "天元之弈|踏雪寻梅"

}, {

"ename": 503,

"cname": "狂铁",

"title": "战车意志",

"new_type": 0,

"hero_type": 1,

"skin_name": "战车意志|命运角斗场|御狮"

}, {

"ename": 504,

"cname": "米莱狄",

"title": "筑城者",

"new_type": 0,

"hero_type": 2,

"skin_name": "筑城者|精准探案法|御霄"

}, {

"ename": 125,

"cname": "元歌",

"title": "无间傀儡",

"new_type": 0,

"hero_type": 4,

"skin_name": "无间傀儡|午夜歌剧院"

}, {

"ename": 510,

"cname": "孙策",

"title": "光明之海",

"new_type": 0,

"hero_type": 3,

"hero_type2": 1,

"skin_name": "光明之海|海之征途|猫狗日记"

}, {

"ename": 137,

"cname": "司马懿",

"title": "寂灭之心",

"new_type": 0,

"hero_type": 4,

"hero_type2": 2,

"skin_name": "寂灭之心|魇语军师"

}, {

"ename": 509,

"cname": "盾山",

"title": "无尽之盾",

"new_type": 0,

"hero_type": 6,

"hero_type2": 3,

"skin_name": "无尽之盾|极冰防御线"

}, {

"ename": 508,

"cname": "伽罗",

"title": "破魔之箭",

"new_type": 0,

"hero_type": 5,

"skin_name": "破魔之箭|花见巫女"

}, {

"ename": 312,

"cname": "沈梦溪",

"title": "爆弹怪猫",

"new_type": 0,

"hero_type": 2,

"skin_name": "爆弹怪猫|棒球奇才"

}, {

"ename": 507,

"cname": "李信",

"title": "谋世之战",

"new_type": 0,

"hero_type": 1,

"skin_name": "谋世之战|灼热之刃"

}, {

"ename": 513,

"cname": "上官婉儿",

"title": "惊鸿之笔",

"new_type": 0,

"hero_type": 2,

"hero_type2": 4,

"skin_name": "惊鸿之笔|修竹墨客"

}, {

"ename": 515,

"cname": "嫦娥",

"title": "寒月公主",

"new_type": 0,

"hero_type": 2,

"hero_type2": 3,

"skin_name": "寒月公主|露花倒影"

}, {

"ename": 511,

"cname": "猪八戒",

"title": "无忧猛士",

"new_type": 0,

"hero_type": 3,

"skin_name": "无忧猛士|年年有余"

}, {

"ename": 529,

"cname": "盘古",

"title": "破晓之神",

"new_type": 0,

"hero_type": 1,

"skin_name": "破晓之神"

}, {

"ename": 505,

"cname": "瑶",

"title": "鹿灵守心",

"new_type": 0,

"hero_type": 6,

"skin_name": "森"

}, {

"ename": 506,

"cname": "云中君",

"title": "流云之翼",

"new_type": 0,

"hero_type": 4,

"hero_type2": 1,

"skin_name": "荷鲁斯之眼"

}, {

"ename": 522,

"cname": "曜",

"title": "星辰之子",

"new_type": 0,

"hero_type": 1,

"skin_name": "归虚梦演"

}, {

"ename": 518,

"cname": "马超",

"title": "冷晖之枪",

"new_type": 0,

"hero_type": 1,

"hero_type2": 4

}, {

"ename": 523,

"cname": "西施",

"title": "幻纱之灵",

"new_type": 0,

"hero_type": 2,

"skin_name": "幻纱之灵|归虚梦演"

}, {

"ename": 525,

"cname": "鲁班大师",

"title": "神匠",

"new_type": 0,

"hero_type": 6,

"skin_name": "神匠|归虚梦演"

}, {

"ename": 524,

"cname": "蒙犽",

"title": "烈炮小子",

"new_type": 0,

"hero_type": 5,

"skin_name": "烈炮小子|归虚梦演"

}, {

"ename": 531,

"cname": "镜",

"title": "破镜之刃",

"new_type": 0,

"hero_type": 4,

"skin_name": "破镜之刃|冰刃幻境"

}, {

"ename": 527,

"cname": "蒙恬",

"title": "秩序统将",

"new_type": 0,

"hero_type": 1,

"hero_type2": 3,

"skin_name": "秩序统将|秩序猎龙将"

}, {

"ename": 533,

"cname": "阿古朵",

"title": "山林之子",

"new_type": 0,

"hero_type": 3,

"hero_type2": 6,

"skin_name": "山林之子"

},{

"ename": 536,

"cname": "夏洛特",

"title": "玫瑰剑士",

"new_type": 0,

"hero_type": 1,

"skin_name": "玫瑰剑士"

},{

"ename": 528,

"cname": "澜",

"title": "鲨之猎刃",

"new_type": 0,

"hero_type": 4,

"skin_name": "鲨之猎刃"

},{

"ename": 537,

"cname": "司空震",

"title": "雷霆之王",

"new_type": 0,

"hero_type": 1,

"hero_type2": 2,

"skin_name": "雷霆之王"

},{

"ename": 155,

"cname": "艾琳",

"title": "精灵之舞",

"new_type": 1,

"hero_type": 5,

"skin_name": "精灵之舞"}]

View Code

可以看出 ename 是英雄ID cname 是英雄名称
这就很简单了 可以这样写

#读取英雄列表

url = \'http://pvp.qq.com/web201605/js/herolist.json\'

content = requests.get(url)

hero_json = content .json()

2.获取英雄皮肤

根据上一个页面点进来英雄详情页 可以看到连接为  https://pvp.qq.com/web201605/herodetail/{英雄ID}.shtml

查看代码定位到div.pic-pf-list 为显示英雄皮肤容器 进一步看到 page.js 的一段代码


//完整链接为 https://pvp.qq.com/web201706/herodetail/cssjs/page.js
var skinlist = $(\'.pic-pf-list\'),

allname = skinlist.data(\'imgname\').split(\'|\'),

skinbg = $(\'.zk-con1\'),

herotitle = $(\'.cover-title\'), t = true, pf = $(".pic-pf .pf"),

surl = \'//game.gtimg.cn/images/yxzj/img201606/heroimg/\' + ename + \'/\' + ename,

burl = "//game.gtimg.cn/images/yxzj/img201606/skin/hero-info/" + ename + \'/\' + ename,

shtml = \'\',

skins = [],

nameAnd;

for (var i = 0; i < allname.length; i++) {

nameAnd = allname[i].split(\'&\')

if (nameAnd.length > 1) {

skins.push({

name: nameAnd[0],

icon: nameAnd[1]

})

} else {

skins.push({

name: nameAnd[0],

icon: 0

})

}

}

function wrap (a, b) {

for (var i = a; i < b; i++) {

var bskin = burl + "-bigskin-" + (i + 1) + ".jpg";

shtml += \'<li><i\' + (i == 0 ? \' class="curr"\' : \'\') + \'><img src="\' + surl + \'-smallskin-\' + (i + 1) + \'.jpg" alt="" data-imgname="\' + bskin + \'" data-title="\' + skins[i].name + \'" data-icon="\' + skins[i].icon + \'"></i><p>\' + skins[i].name + \'</p></li>\';

};

}

wrap(0, skins.length);

skinlist.html(shtml);

 

这里可以看出皮肤地址为 //game.gtimg.cn/images/yxzj/img201606/skin/hero-info/{英雄ID}/{英雄ID}-bigskin-{自增ID}.jpg
数量通过分割 skinlist.data(\'imgname\') 属性按‘|’分割获取(看下面红色部分)

   <ul class="pic-pf-list pic-pf-list3" data-imgname="鲨之猎刃&0|孤猎&0">

  那么代码就可以这样写了

  

#读取英雄详情

url = \'https://pvp.qq.com/web201605/herodetail/{英雄ID}.shtml

content = requests.get(url)

# 改变编码

content.encoding=\'gb2312\'

soup=BeautifulSoup(content.text,\'lxml\')

data = soup.find(class_=\'pic-pf-list3\')[\'data-imgname\']

index = 0

for val in data.split(\'|\'):

index += 1

imgrul = \'http://game.gtimg.cn/images/yxzj/img201606/skin/hero-info/{英雄ID}/{英雄ID}-bigskin-{index}.jpg

print(imgrul )

下一步保存就可以了 

完整代码如下

import requests

import json

import os

from bs4 import BeautifulSoup

#读取英雄列表

url = \'http://pvp.qq.com/web201605/js/herolist.json\'

content = requests.get(url)

for v in content.json():

ename = v[\'ename\']

cname = v[\'cname\']

#创建目录

savePath = os.path.join(os.path.abspath(\'./hero_img\'), cname)

if not os.path.exists(savePath):

print(\'创建目录%s\'%(savePath))

os.makedirs(savePath)

#读取英雄详情

url = \'https://pvp.qq.com/web201605/herodetail/%d.shtml\'%(ename)

content = requests.get(url)

# 改变编码

content.encoding=\'gb2312\'

soup=BeautifulSoup(content.text,\'lxml\')

data = soup.find(class_=\'pic-pf-list3\')[\'data-imgname\']

#print(data)

# 读取记录

index = 0

for val in data.split(\'|\'):

index += 1

img = val.split(\'&\')

imgUrl = \'http://game.gtimg.cn/images/yxzj/img201606/skin/hero-info/%d/%d-bigskin-%d.jpg\'%(ename,ename,index)

imgName = "%s_%s.jpg"%(img[0],img[1])

imgContent = requests.get(imgUrl)

if imgContent.status_code == 200:

with open(file=os.path.join(savePath, imgName),mode=\'wb\') as f:

f.write(imgContent.content)

结果打印如下

创建目录C:\Users\Administrator\pytest\hero_img\小乔

创建目录C:\Users\Administrator\pytest\hero_img\赵云

创建目录C:\Users\Administrator\pytest\hero_img\墨子

创建目录C:\Users\Administrator\pytest\hero_img\妲己

创建目录C:\Users\Administrator\pytest\hero_img\嬴政

创建目录C:\Users\Administrator\pytest\hero_img\孙尚香

创建目录C:\Users\Administrator\pytest\hero_img\鲁班七号

创建目录C:\Users\Administrator\pytest\hero_img\庄周

创建目录C:\Users\Administrator\pytest\hero_img\刘禅

创建目录C:\Users\Administrator\pytest\hero_img\高渐离

创建目录C:\Users\Administrator\pytest\hero_img\阿轲

创建目录C:\Users\Administrator\pytest\hero_img\钟无艳

创建目录C:\Users\Administrator\pytest\hero_img\孙膑

创建目录C:\Users\Administrator\pytest\hero_img\扁鹊

创建目录C:\Users\Administrator\pytest\hero_img\白起

创建目录C:\Users\Administrator\pytest\hero_img\芈月

创建目录C:\Users\Administrator\pytest\hero_img\吕布

创建目录C:\Users\Administrator\pytest\hero_img\周瑜

创建目录C:\Users\Administrator\pytest\hero_img\夏侯惇

创建目录C:\Users\Administrator\pytest\hero_img\甄姬

创建目录C:\Users\Administrator\pytest\hero_img\曹操

创建目录C:\Users\Administrator\pytest\hero_img\典韦

创建目录C:\Users\Administrator\pytest\hero_img\宫本武藏

创建目录C:\Users\Administrator\pytest\hero_img\李白

创建目录C:\Users\Administrator\pytest\hero_img\马可波罗

创建目录C:\Users\Administrator\pytest\hero_img\狄仁杰

创建目录C:\Users\Administrator\pytest\hero_img\达摩

创建目录C:\Users\Administrator\pytest\hero_img\项羽

创建目录C:\Users\Administrator\pytest\hero_img\武则天

创建目录C:\Users\Administrator\pytest\hero_img\老夫子

创建目录C:\Users\Administrator\pytest\hero_img\关羽

创建目录C:\Users\Administrator\pytest\hero_img\貂蝉

创建目录C:\Users\Administrator\pytest\hero_img\安琪拉

创建目录C:\Users\Administrator\pytest\hero_img\程咬金

创建目录C:\Users\Administrator\pytest\hero_img\露娜

创建目录C:\Users\Administrator\pytest\hero_img\姜子牙

创建目录C:\Users\Administrator\pytest\hero_img\刘邦

创建目录C:\Users\Administrator\pytest\hero_img\韩信

创建目录C:\Users\Administrator\pytest\hero_img\王昭君

创建目录C:\Users\Administrator\pytest\hero_img\兰陵王

创建目录C:\Users\Administrator\pytest\hero_img\花木兰

创建目录C:\Users\Administrator\pytest\hero_img\张良

创建目录C:\Users\Administrator\pytest\hero_img\不知火舞

创建目录C:\Users\Administrator\pytest\hero_img\娜可露露

创建目录C:\Users\Administrator\pytest\hero_img\橘右京

创建目录C:\Users\Administrator\pytest\hero_img\亚瑟

创建目录C:\Users\Administrator\pytest\hero_img\孙悟空

创建目录C:\Users\Administrator\pytest\hero_img\牛魔

创建目录C:\Users\Administrator\pytest\hero_img\后羿

创建目录C:\Users\Administrator\pytest\hero_img\刘备

创建目录C:\Users\Administrator\pytest\hero_img\张飞

创建目录C:\Users\Administrator\pytest\hero_img\李元芳

创建目录C:\Users\Administrator\pytest\hero_img\虞姬

创建目录C:\Users\Administrator\pytest\hero_img\钟馗

创建目录C:\Users\Administrator\pytest\hero_img\成吉思汗

创建目录C:\Users\Administrator\pytest\hero_img\杨戬

创建目录C:\Users\Administrator\pytest\hero_img\雅典娜

创建目录C:\Users\Administrator\pytest\hero_img\蔡文姬

创建目录C:\Users\Administrator\pytest\hero_img\太乙真人

创建目录C:\Users\Administrator\pytest\hero_img\哪吒

创建目录C:\Users\Administrator\pytest\hero_img\诸葛亮

创建目录C:\Users\Administrator\pytest\hero_img\黄忠

创建目录C:\Users\Administrator\pytest\hero_img\大乔

创建目录C:\Users\Administrator\pytest\hero_img\东皇太一

创建目录C:\Users\Administrator\pytest\hero_img\干将莫邪

创建目录C:\Users\Administrator\pytest\hero_img\鬼谷子

创建目录C:\Users\Administrator\pytest\hero_img\铠

创建目录C:\Users\Administrator\pytest\hero_img\百里守约

创建目录C:\Users\Administrator\pytest\hero_img\百里玄策

创建目录C:\Users\Administrator\pytest\hero_img\苏烈

创建目录C:\Users\Administrator\pytest\hero_img\梦奇

创建目录C:\Users\Administrator\pytest\hero_img\女娲

创建目录C:\Users\Administrator\pytest\hero_img\明世隐

创建目录C:\Users\Administrator\pytest\hero_img\公孙离

创建目录C:\Users\Administrator\pytest\hero_img\杨玉环

创建目录C:\Users\Administrator\pytest\hero_img\裴擒虎

创建目录C:\Users\Administrator\pytest\hero_img\弈星

创建目录C:\Users\Administrator\pytest\hero_img\狂铁

创建目录C:\Users\Administrator\pytest\hero_img\米莱狄

创建目录C:\Users\Administrator\pytest\hero_img\元歌

创建目录C:\Users\Administrator\pytest\hero_img\孙策

创建目录C:\Users\Administrator\pytest\hero_img\司马懿

创建目录C:\Users\Administrator\pytest\hero_img\盾山

创建目录C:\Users\Administrator\pytest\hero_img\伽罗

创建目录C:\Users\Administrator\pytest\hero_img\沈梦溪

创建目录C:\Users\Administrator\pytest\hero_img\李信

创建目录C:\Users\Administrator\pytest\hero_img\上官婉儿

创建目录C:\Users\Administrator\pytest\hero_img\嫦娥

创建目录C:\Users\Administrator\pytest\hero_img\猪八戒

创建目录C:\Users\Administrator\pytest\hero_img\盘古

创建目录C:\Users\Administrator\pytest\hero_img\瑶

创建目录C:\Users\Administrator\pytest\hero_img\云中君

创建目录C:\Users\Administrator\pytest\hero_img\曜

创建目录C:\Users\Administrator\pytest\hero_img\马超

创建目录C:\Users\Administrator\pytest\hero_img\西施

创建目录C:\Users\Administrator\pytest\hero_img\鲁班大师

创建目录C:\Users\Administrator\pytest\hero_img\蒙犽

创建目录C:\Users\Administrator\pytest\hero_img\镜

创建目录C:\Users\Administrator\pytest\hero_img\蒙恬

创建目录C:\Users\Administrator\pytest\hero_img\阿古朵

创建目录C:\Users\Administrator\pytest\hero_img\夏洛特

创建目录C:\Users\Administrator\pytest\hero_img\澜

创建目录C:\Users\Administrator\pytest\hero_img\司空震

创建目录C:\Users\Administrator\pytest\hero_img\艾琳

以上是 python 爬取王者荣耀全套皮肤壁纸 的全部内容, 来源链接: utcz.com/z/387468.html

回到顶部