鱼C论坛

 找回密码
 立即注册
查看: 1323|回复: 2

[作品展示] 爬取王者所有英雄及下载头像

[复制链接]
发表于 2020-5-8 12:58:26 | 显示全部楼层 |阅读模式

马上注册,结交更多好友,享用更多功能^_^

您需要 登录 才可以下载或查看,没有账号?立即注册

x
  1. import requests
  2. import re
  3. import time
  4. from bs4 import BeautifulSoup
  5. from urllib.request import urlretrieve
  6. import os
  7. print("=============================")
  8. Url = "https://pvp.qq.com/web201605/herolist.shtml"
  9. headers = {
  10.     "user-agent": "Mozilla/5.0 (Windows NT 6.1; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/83.0.4103.14 Safari/537.36 Edg/83.0.478.13"
  11. }
  12. cwd = os.getcwd()
  13. def here_name():
  14.     try:
  15.         os.mkdir("王者头像")
  16.     except:
  17.         pass
  18.     finally:
  19.         x = 1
  20.         global cwd
  21.         html_ = requests.get(Url, headers=headers).content.decode("gbk")
  22.         heros = re.findall('height="91" alt="(.*?)">', html_, re.S)
  23.         heros.pop()
  24.         with open(cwd + "\\王者头像\\hero","w",encoding="utf-8") as f:
  25.             for hero in heros:
  26.                 f.write(hero+"\n")
  27.         print("=============================")
  28.         print("总共有%d" % (len(heros)))
  29.         pictures = re.findall('<img.*?src="(.*?)"',html_,re.S)
  30.         for picture in pictures:
  31.             if picture[:2]  == "//":
  32.                 urlretrieve("http:"+picture,cwd+"\\王者头像\"+str(x)+".jpg")
  33.                 x+=1
  34.             else:
  35.                 pass


  36. if __name__ == "__main__":
  37.     here_name()
  38. """
  39. <li><a href="herodetail/105.shtml" target="_blank"><img
  40.                                         src="//game.gtimg.cn/images/yxzj/img201606/heroimg/105/105.jpg" width="91"
  41.                                         height="91" alt="廉颇">廉颇</a></li>"""
复制代码

那个廉颇那个是我懒得删了
小甲鱼最新课程 -> https://ilovefishc.com
回复

使用道具 举报

发表于 2020-5-8 12:59:45 | 显示全部楼层
虽然不打农药,但是也来看看
小甲鱼最新课程 -> https://ilovefishc.com
回复 支持 反对

使用道具 举报

 楼主| 发表于 2020-5-8 13:02:46 | 显示全部楼层
老八秘制 发表于 2020-5-8 12:59
虽然不打农药,但是也来看看

我才发了不到十秒...
小甲鱼最新课程 -> https://ilovefishc.com
回复 支持 反对

使用道具 举报

您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

小黑屋|手机版|Archiver|鱼C工作室 ( 粤ICP备18085999号-1 | 粤公网安备 44051102000585号)

GMT+8, 2025-6-18 22:19

Powered by Discuz! X3.4

© 2001-2023 Discuz! Team.

快速回复 返回顶部 返回列表