【Python爬虫实战】你不必到处找数据,你完全可以自己爬之Python批量采集图虫网摄影师高清美照,听说~你喜欢御姐...(爬图神器)

454 阅读2分钟

前言

怎么批量保存网页图片?

有时候在网页中看到很多美图其中有很多自己喜欢的图片素材或壁纸,一张纸一张下载保存未

免太低效了。

今天,小编为果粉朋友分享一个“爬图片”快捷指令,借助它可以一键下载保存浏览者网页中的

所有图片,让我们愉快的开始吧~

爬图神器——Python批量采集图虫网摄影师高清美照,听说:你喜欢的美图(美女姐姐、小萝

莉、御姐......)都在这里鸭~(我知道我不说,我偷偷教你们)

正文

本次内容学到的知识点有哪些呢?

动态页面分析  动态数据抓包  requests   

一、运行环境

 1)开发环境 

 版 本: python 3.8  编辑器:pycharm 2022.3.2  

 requests >>> pip install requests 

 +python安装包 安装教程视频

+pycharm 社区版 专业版 及 激活码免费找我拿即可 

2)模块安装 

pip install 模块名 镜像源安装 pip install -i pypi.douban.com/simple/ +模块名 Python 安 

 装包 安装教程视频 pycharm 社区版 专业版 及 激活码免费找我拿即可 ! (各种版本的都

有,可以一整套直接分享滴~)

 按住键盘 win + r, 输入cmd回车 打开命令行窗口, 在里面输入 pip install 模块名 。

二、代码展示

1)​主程序

"""
import requests
import parsel


headers = {
    'cookie': 'PHPSESSID=a6phn4ue7180gv3lu9ptdefu15; webp_enabled=1; lang=zh; log_web_id=6142749383; ttcid=33eb5efe64ce4d7ab777615d594b674c35; tt_scid=iiNP.JKSffhMzg6Ij8Wvc1QUUUp34mxhxh8tTbKXVDKz.iGDujlYmC9Y8vT-OaVDdb39',
    'referer': 'https://tuchong.com/tags/Cosplay/',
    'user-agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/110.0.0.0 Safari/537.36',
}
main_url = 'https://tuchong.com/explore/'
html_data = requests.get(main_url).text
select = parsel.Selector(html_data)
two_url_list = select.css('.tags-all-link::attr(href)').getall()
for two_url in two_url_list:
    # 'https://tuchong.com/categories/subject/'
    three_url = 'https://tuchong.com/rest/tag-categories/' + two_url.split('/')[-2]
    print(three_url)
    pages = requests.get(three_url).json()['data']['pages']
    for page in range(1, pages+1):
        three_url = 'https://tuchong.com/rest/tag-categories/' + two_url.split('/')[-2] + f'?page={page}&count=20'
        tag_list = requests.get(three_url).json()['data']['tag_list']
        for tag in tag_list:
            tag_url = tag['url']
            tag_name = tag_url.split('/')[-2]
            for page in range(1, 101):
                # 请求与响应
                url = f'https://tuchong.com/rest/tags/{tag_name}/posts?page={page}&count=20&order=weekly'
                json_data = requests.get(url=url, headers=headers).json()
                postList = json_data['postList']
                for post in postList:
                    author_id = post['author_id']
                    for img in post['images']:
                        img_id_str = img['img_id_str']
                        img_url = f'https://photo.tuchong.com/{author_id}/f/{img_id_str}.jpg'
                        print(img_url)

2)效果展示

下载中——

​图片展示——

总结

好啦,今天在内容就到这里正式结束了哈!想要源码的滴滴我即可啦,小编随时给大家发资料

想要更多美图壁纸直接找我也可鸭 嘿嘿,还是我懂你们叭