当前位置: 首页 > news >正文

vscode 编写爬虫爬取王者荣耀壁纸

网上关于爬虫大部分教程和编辑器用的都不是vscode ,此教程用到了vscode、Python、bs4、requests。

vscode配置Python安装环境可以看看这个大佬的教程 03-vscode安装和配置_哔哩哔哩_bilibili

vscode配置爬虫环境可以参考这个大佬的教程【用Vscode实现简单的python爬虫】从安装到配置环境变量到简单爬虫以及python中pip和request,bs4安装_vscode爬虫-CSDN博客

爬虫代码如下


#按照指令升级pip库,如果无法解析pip指令说明系统变量环境path中缺少了Python的路径,解决办法:https://zhuanlan.zhihu.com/p/655640807
#发送请求的模块  pip install requests
import requests
#解析HTML的模块  pip install bs4
from bs4 import BeautifulSoup
import os
import re headers1={"User-Agent":"Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/119.0.0.0 Safari/537.36 Edg/119.0.0.0"}def requests_url(req_url):response= requests.get(req_url,headers=headers1)response.encoding='gbk'   #网页编码gbkreturn response.text#获取英雄列表里面的英雄详情页网址以及英雄编号
#https://pvp.qq.com/web201605/herolist.shtml
#解析标签,获取到英雄详情页以及英雄名字<a href="herodetail/lianpo.shtml" target="_blank"><img src="//game.gtimg.cn/images/yxzj/img201606/heroimg/105/105.jpg" width="91" height="91" alt="廉颇">廉颇</a>
#
herolist_resp= requests_url("https://pvp.qq.com/web201605/herolist.shtml")
soup =  BeautifulSoup(herolist_resp,"html.parser")
ul = soup.find_all("ul",attrs={"class":"herolist clearfix"})
icon_list = ul[0].find_all("a")for i,n in enumerate(icon_list):hrefs=n.get("href")   url = "https://pvp.qq.com/web201605/"+ hrefsid = re.findall(r'\d+',hrefs)[0]    #获取英雄编号imgs=n.findAll('img')[0]c_name= imgs.get("alt")local_path = "王者荣耀\\"+c_name+"\\"   #创建英雄文件夹if not os.path.exists(local_path):os.makedirs(local_path)#获取详情页herodetail_resp = requests_url(url)soup = BeautifulSoup(herodetail_resp,"html.parser")ul = soup.findAll("ul",attrs={"class":"pic-pf-list pic-pf-list3"})#data-imgname属性获取names = ul[0].get("data-imgname")names=[name[0:name.index('&')]for name in names.split('|')]print(names)#提取皮肤名字for i,n in enumerate(names) :print (n)#   for num in  range(105,108):    #563#response = requests.get(f"https://game.gtimg.cn/images/yxzj/img201606/skin/hero-info/{num}/{num}-bigskin-1.jpg",headers=headers1)response = requests.get(f"https://game.gtimg.cn/images/yxzj/img201606/skin/hero-info/{id}/{id}-bigskin-{i+1}.jpg",headers=headers1)#保存图片with open (local_path+f"{n}.jpg",'wb') as f:f.write(response.content)

此爬虫支持不同英雄的壁纸根据皮肤名称分类存放,具体效果可以观看B站视频vscode编写Python爬虫,爬取王者荣耀皮肤壁纸_哔哩哔哩_bilibili。

http://www.lryc.cn/news/257170.html

相关文章:

  • spring boot + uniapp 微信公众号 jsapi 支付
  • 【数学建模】《实战数学建模:例题与讲解》第九讲-时间序列分析(含Matlab代码)
  • 大话数据结构-查找-有序表查找
  • Qt实现二维码生成和识别
  • MyBatisX插件
  • 《C++20设计模式》学习笔记---原型模式
  • SpringBootAdmin设置邮件通知
  • 深度解析IP应用场景API:提升风险控制与反欺诈能力
  • Java连接数据库增删改查-MyBatis
  • 在国内,现在月薪1万是什么水平?
  • 【Python网络爬虫入门教程1】成为“Spider Man”的第一课:HTML、Request库、Beautiful Soup库
  • 燕千云汇联易联袂出击:护航医企合规,丝滑内外协作
  • 【线性代数与矩阵论】Jordan型矩阵
  • laravel的ORM 对象关系映射
  • 049:VUE 引入jquery的方法和配置
  • Qt设置类似于qq登录页面
  • 【GDB】
  • 深入了解Java Duration类,对时间的精细操作
  • Python:核心知识点整理大全5-笔记
  • 预训练(pre-learning)、微调(fine-tuning)、迁移学习(transfer learning)
  • 王道数据结构课后代码题 p149 第8—— 12(c语言代码实现)
  • Nginx服务优化以及防盗链
  • 20231210 随机矩阵和M矩阵
  • Linux(centos)学习笔记(初学)
  • ECharts标题字体大小自适应变化
  • 解决使用pnpm安装时Sharp模块报错的方法
  • Redis 数据的持久化 RDB、AOF、RDB + AOF、No persistence 各自优缺点
  • 回味童年经典游戏的项目
  • Electron[5] 渲染进程和主进程
  • 基于Java SSM框架实现大学生校园兼职系统项目【项目源码+论文说明】