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

news/2024/7/19 11:54:28 标签: vscode, 爬虫, ide

网上关于爬虫大部分教程和编辑器用的都不是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'   #网页编码gbk
    return 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/"+ hrefs

    id = 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.niftyadmin.cn/n/5253569.html

相关文章

gitbash下载安装

参考教程 零、下载 官网地址 2.43.0win64 链接&#xff1a;https://pan.baidu.com/s/16urs_nmky7j20-qNzUTTkg 提取码&#xff1a;7jaq 一、安装 图标组件&#xff08;Additional icons&#xff09;&#xff1a;选择是否创建桌面快捷方式&#xff1b;桌面浏览&#xff08;Win…

Qt设置类似于qq登录页面

头文件 #ifndef WIDGET_H #define WIDGET_H#include <QWidget> #include <QWindow> #include <QIcon> #include <QLabel> #include <QMovie> #include <QLineEdit> #include <QPushButton>QT_BEGIN_NAMESPACE namespace Ui { class…

内测分发是什么?十年的前端开发者带你了解

内测分发是软件开发过程中的一个阶段&#xff0c;特别指软件还未完全完成或准备对外广泛发布前&#xff0c;向一定范围的用户群体提供该软件版本的测试机会&#xff0c;以便收集反馈和修复潜在的问题。在讲解内测分发之前&#xff0c;我们需要明确几个相关概念&#xff1a; 软件…

区块链媒体宣发:揭示优势与趋势,引领信息传播新时代

在数字化潮流中&#xff0c;区块链技术正以惊人的速度改变着传媒行业的格局。从区块链媒体宣发中获得的种种优势和未来的趋势&#xff0c;不仅为企业带来了新的推广途径&#xff0c;也在信息传播领域掀起了一场革命。本文将深入探讨区块链媒体宣发的优势以及未来的发展趋势。 1…

Vue 3项目的运行过程

概述&#xff1a; 使用Vite构建Vue 3项目后&#xff0c;当执行yarn dev命令启动服务时&#xff0c;项目就会运行起来&#xff0c;该项目会通过src\main.js文件将src\App.vue组件渲染到index.html文件的指定区域。 文件介绍&#xff1a; src\App.vue文件 Vue 3项目是由各种组件…

Mybatis与Spring结合深探——MapperFactoryBean的奥秘

文章目录 前言MapperFactoryBean的工作原理底层实现剖析MapperFactoryBean的checkDaoConfig()方法总结 MapperFactoryBean的getObject()方法 思考联想后续 系列相关相关文章究竟FactoryBean是什么&#xff1f;深入理解Spring的工厂神器超硬核解析Mybatis动态代理原理&#xff0…

第一章数据结构绪论

1.1数据结构的定义 1.2基本概念和术语 数据 数据元素 数据项 数据对象 数据结构 1.3逻辑结构与物理结构 按照观点不同&#xff0c;我们把数据结构分为逻辑结构图物理结构 逻辑结构 物理结构 1.4抽象数据结构 数据类型 抽象数据类型 注&#xff1a;给出描述数据类型的基本格…

ElasticSearch之cat repositories API

命令样例如下&#xff1a; curl -X GET "https://localhost:9200/_cat/repositories?vtrue&pretty" --cacert $ES_HOME/config/certs/http_ca.crt -u "elastic:ohCxPHQBEs5*lo7F9"执行结果输出如下&#xff1a; id type repo1 fs repo2 s3查…