python抓取异步数据(加载更多类型的),并下载图片,保存到文件夹,实例

源码:


{"subjects":[{"episodes_info":"","rate":"8.8","cover_x":3000,"title":"奥本海默","url":"https:\/\/movie.douban.com\/subject\/35593344\/","playable":true,"cover":"https://img3.doubanio.com\/view\/photo\/s_ratio_poster\/public\/p2897210097.webp","id":"35593344","cover_y":4445,"is_new":false},{"episodes_info":"","rate":"6.2","cover_x":2126,"title":"坚如磐石","url":"https:\/\/movie.douban.com\/subject\/33447633\/","playable":true,"cover":"https://img3.doubanio.com\/view\/photo\/s_ratio_poster\/public\/p2896319483.webp","id":"33447633","cover_y":2976,"is_new":false},{"episodes_info":"","rate":"8.1","cover_x":1400,"title":"3天的休假","url":"https:\/\/movie.douban.com\/subject\/34880019\/","playable":false,"cover":"https://img3.doubanio.com\/view\/photo\/s_ratio_poster\/public\/p2899692123.webp","id":"34880019","cover_y":2000,"is_new":true},{"episodes_info":"","rate":"6.0","cover_x":1500,"title":"断网假期","url":"https:\/\/movie.douban.com\/subject\/35151492\/","playable":false,"cover":"https://img2.doubanio.com\/view\/photo\/s_ratio_poster\/public\/p2899786881.webp","id":"35151492","cover_y":2222,"is_new":false},{"episodes_info":"","rate":"7.1","cover_x":1500,"title":"五月十二月","url":"https:\/\/movie.douban.com\/subject\/35295277\/","playable":false,"cover":"https://img9.doubanio.com\/view\/photo\/s_ratio_poster\/public\/p2898667786.webp","id":"35295277","cover_y":2222,"is_new":false},{"episodes_info":"","rate":"8.1","cover_x":1350,"title":"可怜的东西","url":"https:\/\/movie.douban.com\/subject\/35350109\/","playable":false,"cover":"https://img1.doubanio.com\/view\/photo\/s_ratio_poster\/public\/p2897485958.webp","id":"35350109","cover_y":2000,"is_new":false},{"episodes_info":"","rate":"6.8","cover_x":5690,"title":"饥饿游戏:鸣鸟与蛇之歌","url":"https:\/\/movie.douban.com\/subject\/34438298\/","playable":false,"cover":"https://img3.doubanio.com\/view\/photo\/s_ratio_poster\/public\/p2900895923.webp","id":"34438298","cover_y":8611,"is_new":false},{"episodes_info":"","rate":"8.0","cover_x":589,"title":"枯叶","url":"https:\/\/movie.douban.com\/subject\/35928797\/","playable":false,"cover":"https://img3.doubanio.com\/view\/photo\/s_ratio_poster\/public\/p2902743747.webp","id":"35928797","cover_y":869,"is_new":false},{"episodes_info":"","rate":"6.8","cover_x":4050,"title":"梦想情景","url":"https:\/\/movie.douban.com\/subject\/36076190\/","playable":false,"cover":"https://img2.doubanio.com\/view\/photo\/s_ratio_poster\/public\/p2898316441.webp","id":"36076190","cover_y":6000,"is_new":false},{"episodes_info":"","rate":"6.5","cover_x":683,"title":"家庭计划","url":"https:\/\/movie.douban.com\/subject\/36127988\/","playable":false,"cover":"https://img3.doubanio.com\/view\/photo\/s_ratio_poster\/public\/p2900158983.webp","id":"36127988","cover_y":1024,"is_new":false},{"episodes_info":"","rate":"7.3","cover_x":1080,"title":"看不见的朋友","url":"https:\/\/movie.douban.com\/subject\/35954480\/","playable":false,"cover":"https://img1.doubanio.com\/view\/photo\/s_ratio_poster\/public\/p2898943699.webp","id":"35954480","cover_y":1543,"is_new":false},{"episodes_info":"","rate":"8.3","cover_x":2600,"title":"长安三万里","url":"https:\/\/movie.douban.com\/subject\/36035676\/","playable":true,"cover":"https://img1.doubanio.com\/view\/photo\/s_ratio_poster\/public\/p2893820209.webp","id":"36035676","cover_y":4153,"is_new":false},{"episodes_info":"","rate":"8.0","cover_x":3000,"title":"芭比","url":"https:\/\/movie.douban.com\/subject\/4058939\/","playable":true,"cover":"https://img9.doubanio.com\/view\/photo\/s_ratio_poster\/public\/p2895679456.webp","id":"4058939","cover_y":4376,"is_new":false},{"episodes_info":"","rate":"6.8","cover_x":5009,"title":"好像也没那么热血沸腾","url":"https:\/\/movie.douban.com\/subject\/35882742\/","playable":true,"cover":"https://img1.doubanio.com\/view\/photo\/s_ratio_poster\/public\/p2898557668.webp","id":"35882742","cover_y":8000,"is_new":false},{"episodes_info":"","rate":"5.9","cover_x":902,"title":"我爸没说的那件事","url":"https:\/\/movie.douban.com\/subject\/26661179\/","playable":true,"cover":"https://img3.doubanio.com\/view\/photo\/s_ratio_poster\/public\/p2899801207.webp","id":"26661179","cover_y":1280,"is_new":false},{"episodes_info":"","rate":"8.5","cover_x":2000,"title":"蜘蛛侠:纵横宇宙","url":"https:\/\/movie.douban.com\/subject\/30391186\/","playable":true,"cover":"https://img3.doubanio.com\/view\/photo\/s_ratio_poster\/public\/p2892315297.webp","id":"30391186","cover_y":2963,"is_new":false},{"episodes_info":"","rate":"9.1","cover_x":1234,"title":"万物生灵:2023圣诞特别集","url":"https:\/\/movie.douban.com\/subject\/35729996\/","playable":false,"cover":"https://img3.doubanio.com\/view\/photo\/s_ratio_poster\/public\/p2902514302.webp","id":"35729996","cover_y":1730,"is_new":false},{"episodes_info":"","rate":"7.6","cover_x":2000,"title":"过往人生","url":"https:\/\/movie.douban.com\/subject\/34963356\/","playable":false,"cover":"https://img9.doubanio.com\/view\/photo\/s_ratio_poster\/public\/p2897238625.webp","id":"34963356","cover_y":3000,"is_new":false},{"episodes_info":"","rate":"6.2","cover_x":1665,"title":"瞒天过海","url":"https:\/\/movie.douban.com\/subject\/35192611\/","playable":false,"cover":"https://img2.doubanio.com\/view\/photo\/s_ratio_poster\/public\/p2901526491.webp","id":"35192611","cover_y":2362,"is_new":false},{"episodes_info":"","rate":"6.6","cover_x":1500,"title":"杀手","url":"https:\/\/movie.douban.com\/subject\/2998451\/","playable":false,"cover":"https://img1.doubanio.com\/view\/photo\/s_ratio_poster\/public\/p2897454450.webp","id":"2998451","cover_y":2222,"is_new":false}]}

抓取代码:

# 抓取异步数据(加载更多类型的),并下载图片,保存到文件夹
import requests
url = 'https://movie.douban.com/j/search_subjects?type=movie&tag=%E7%83%AD%E9%97%A8&sort=recommend&page_limit=20&page_start=20'
headers = {
    'User-Agent':'Mozilla/5.0 (Windows NT 10.0; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/114.0.5735.289 Safari/537.36'
}
response = requests.get(url,headers=headers)
# print(response)
# 输出:<Response [200]>
# print(type(response.json()))
# 输出:<class 'dict'>
# print(response.json())
# 输出:一个字典:{'subjects': [{'episodes_info': '', 'rate': '8.8', 'cover_x': 3000, 'title': '奥本海默',
subjects = response.json()['subjects']
# print(type(subjects))
# 输出:<class 'list'>
for i in subjects:
    # print(i)
    # print(type(i))
    # 输出:<class 'dict'>
    # 得到名称
    name = i['title']
    # 得到图片链接
    pic_url = i['cover']
    pic = requests.get(pic_url)
    # print(type(pic))
    # 输出结果:<class 'requests.models.Response'>
    # 写到同目录下img文件夹中,以name为命名的jpg图片。
    with open(f'./img/{name}.jpg',mode='wb') as f:
        f.write(pic.content)

输出结果:

 如上图左边文件夹中的图片

本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如若转载,请注明出处:/a/299271.html

如若内容造成侵权/违法违规/事实不符,请联系我们进行投诉反馈qq邮箱809451989@qq.com,一经查实,立即删除!

相关文章

基于 IP 多播的网络会议程序(2024)

1.题目描述 局域网 IP 多播程序&#xff0c;设计一个图形界面的网络会议程序&#xff08;实现文本多播方式即可&#xff09;。 2.演示Demo 3.参考代码 广播发送代码 //服务端 #include <winsock2.h> #include <iostream> #include <list>#pragma comment(l…

IMS基本架构

IP Multimedia Core Network Subsystem (IMS)商用已久&#xff0c;相对于CS domain的语音方案&#xff0c;IMS则是基于IETF定义的会话控制功能与多媒体传输功能通过IP-CAN实现的 全IP完整语音解决方案。 IMS能为无线和有线用户实现语音、视频、消息、数据等服务。便于运营商通过…

基于OpenCV的图像翻转和镜像

我们将解释如何在Python中实现图像的镜像或翻转。大家只需要了解各种矩阵运算和矩阵操作背后的基本数学即可。 01. 依赖包要求 NumPy —用于矩阵运算并对其进行处理。 OpenCV —用于读取图像并将其转换为2D数组&#xff08;矩阵&#xff09;。 Matplotlib —用于将矩阵绘制为…

【CSS】文字描边的三种实现方式

目录 1. 可行的几种方式1.1. text-shadow 描边代码优缺点 1.2. text-stroke 描边实现优缺点 1.3. svg 描边实现优缺点 总结 1. 可行的几种方式 text-shadow–webkit-text-strokesvg 1.1. text-shadow 描边 MDN text-shadow 代码 <div class"text stroke">…

Mybatis简易搭建并查询数据库表内所有数据

搭建步骤 1.在mysql中创建user表&#xff0c;添加数据2.创建maven模块&#xff0c;导入坐标3.在资源文件夹中导入需要用到的logback.xml4.编写MyBatis 核心配置文件->替换连接信息 解决硬编码问题5.编写 SQL映射文件->统一管理sgl语句&#xff0c;解决硬编码问题6.编码定…

软件测试之单元测试、系统测试、集成测试知识总结

一、单元测试的概念 单元测试是对软件基本组成单元进行的测试&#xff0c;如函数或一个类的方法。当然这里的基本单元不仅仅指的是一个函数或者方法&#xff0c;有可能对应多个程序文件中的一组函数。 单元也具有一些基本的属性。比如&#xff1a;明确的功能、规格定义&#…

利用VIN接口实现自动识别车型功能

如何利用vin接口实现自动识别车型功能&#xff0c;首先实现此功能我们来大概分析一下流程图&#xff1a; ## 1-收集VIN信息&#xff1a;用户输入或扫描车辆的VIN码。 ## 2-OCR识别&#xff1a;把用户所扫描的内容进行识别。 ## 3-发起API请求&#xff1a;通过编程语言或工具…

Windows11 - Ubuntu 双系统及 ROS、ROS2 安装

系列文章目录 前言 一、Windows11 - Ubuntu 双系统安装 硬件信息&#xff1a; 设备名称 DESKTOP-B62D6KE 处理器 13th Gen Intel(R) Core(TM) i5-13500H 2.60 GHz 机带 RAM 40.0 GB (39.8 GB 可用) 设备 ID 7673EF86-8370-41D0-8831-84926668C05A 产品 ID 00331-10000-0000…

mysql生成数据库字典文档

项目交付离不开项目数据库字典文档。下面用python轻松生成交付文档字典。 一 生成doc文档数据库字典效果&#xff1a; 1 生成doc文件&#xff0c;如下图&#xff1a; 2 打开文件字典格式内容 &#xff0c;如下图&#xff1a; 二 python生成doc字典文档代码 生成doc数据库字典…

uniapp 文字超出多少字,显示收起全文按钮效果demo(整理)

收起展开 <template><view class"font30 color000 mL30 mR30"><text :class"showFullText ? : clamp-text">{{ text }}</text><view v-if"showToggleBtn && text.length > 42" click"toggleShowFu…

STM32实战之IAP代码升级

目录 1 IAP介绍 2 内存分区 3 整体设计流程图 4 Boot Loader的代码编写 5 APP1代码编写 6 APP2代码编写 stm32内部flash操作相关函数 1 IAP介绍 IAP&#xff08;In Application Programming&#xff09;即在应用编程&#xff0c; IAP 是用户自己的程序在运行过程中…

机器学习周刊第二期:300个机器学习应用案例集

大家好 前文&#xff1a;机器学习项目精选 第一期 继续分享我最近看过并觉得非常硬核的资源&#xff0c;包括Python、机器学习、深度学习、大模型等等。 1、Python编程挑战 地址&#xff1a;https://github.com/Asabeneh/30-Days-Of-Python 30天Python编程挑战是一个逐步学…

c++比Java更不容易失业吗?

c比Java更不容易失业吗&#xff1f; 在开始前我有一些资料&#xff0c;是我根据网友给的问题精心整理了一份「C的资料从专业入门到高级教程」&#xff0c; 点个关注在评论区回复“888”之后私信回复“888”&#xff0c;全部无偿共享给大家&#xff01;&#xff01;&#xff01…

SpringBoot 如何 返回页面

背景 RestController ResponseBody Controller Controller中的方法无法返回jsp页面&#xff0c;或者html&#xff0c;配置的视图解析器 InternalResourceViewResolver不起作用&#xff0c;返回的内容就是Return 里的内容。 Mapping ResponseBody 也会出现同样的问题。 解…

SpringCloud系列篇:入门讲解Spring Cloud是什么

&#x1f973;&#x1f973;Welcome Huihuis Code World ! !&#x1f973;&#x1f973; 接下来看看由辉辉所写的关于SpringCloud的相关操作吧 目录 &#x1f973;&#x1f973;Welcome Huihuis Code World ! !&#x1f973;&#x1f973; 一.Spring Cloud是什么 二.Spring …

java基于vue的音乐播放器的设计与实现论文

摘 要 当下&#xff0c;如果还依然使用纸质文档来记录并且管理相关信息&#xff0c;可能会出现很多问题&#xff0c;比如原始文件的丢失&#xff0c;因为采用纸质文档&#xff0c;很容易受潮或者怕火&#xff0c;不容易备份&#xff0c;需要花费大量的人员和资金来管理用纸质文…

ThinkPHP5多小区物业管理系统源码(支持多小区)

基于 ThinkPHP5 Bootstrap 倾力打造的多小区物业 管理系统源码&#xff0c;操作简单&#xff0c;功能完善&#xff0c;用户体验良好 开发环境PHP7mysql 安装步骤: 1.新建数据库db_estate,还原数据db_estate.sql 2.修改配置文件&#xff1a;application/database.php 3.运…

【已解决】You have an error in your SQL syntax

报错讯息 java.sql.SQLSyntaxErrorException: You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near ‘desc,target_url,sort,status,create_by,modify_by,created,last_update_time FROM…

基于JAYA算法优化的Elman神经网络数据预测 - 附代码

基于JAYA算法优化的Elman神经网络数据预测 - 附代码 文章目录 基于JAYA算法优化的Elman神经网络数据预测 - 附代码1.Elman 神经网络结构2.Elman 神经用络学习过程3.电力负荷预测概述3.1 模型建立 4.基于JAYA优化的Elman网络5.测试结果6.参考文献7.Matlab代码 摘要&#xff1a;针…

2024年阿里云、腾讯云、华为云、LightNode、硅云服务器如何选?怎么买最划算?[最新价格表]

很多小伙伴都有一颗上云的心&#xff0c;包括我自己 有事没事的折腾一下自己的小破站&#xff0c;也挺有意思的&#xff01; 那么&#xff0c;云服务器哪家好&#xff1f;优惠力度哪家大&#xff1f;活动入口哪里进&#xff1f;云服务器如何配置&#xff1f;如何选型&#xf…