python3-张子枫图片爬取

本文介绍了使用Python3爬取某网站张子枫图片的过程。通过分析请求URL,发现pn参数与每页图片数量有关,通过迭代pn值获取多页图片。在抓取过程中,发现当pn达到1350时返回空值,因此在程序中加入判断。最终成功抓取1000多张图片,并提供了百度网盘的链接。
摘要由CSDN通过智能技术生成

Life is short, You need Python

想搞点妹妹图片,一张一张的下载太麻烦…于是决定爬上一爬
目标网站:
分析目标网站,调节到移动模式,进行抓包分析,不难发现所有图片均以json字符串从服务端返回,这里怎么分析就不多介绍

在这里插入图片描述
分析单个request url:
反正就是很长的一串 一大堆参数 反正不知道是干嘛的 鼠标一直下滑 发现出现多个类似的请求url
在这里插入图片描述
比较多个 request url:
在这里插入图片描述
这里复制出来一部分:

Request URL:
https://image.baidu.com/search/acjson?tn=resultjson_com&ipn=rj&ct=201326592&is=&fp=result&queryWord=%E5%BC%A0%E5%AD%90%E6%9E%AB%E5%9B%BE%E7%89%87&cl=2&lm=-1&ie=utf-8&oe=utf-8&adpicid=&st=&z=&ic=&hd=&latest=&copyright=&word=%E5%BC%A0%E5%AD%90%E6%9E%AB%E5%9B%BE%E7%89%87&s=&se=&tab=&width=&height=&face=&istype=&qc=&nc=&fr=&expermode=&force=&cg=star&pn=210&rn=30&gsm=d2&1599125756815=
Request URL:
https://image.baidu.com/search/acjson?tn=resultjson_com&ipn=rj&ct=201326592&is=&fp=result&queryWord=%E5%BC%A0%E5%AD%90%E6%9E%AB%E5%9B%BE%E7%89%87&cl=2&lm=-1&ie=utf-8&oe=utf-8&adpicid=&st=&z=&ic=&hd=&latest=&copyright=&word=%E5%
好的,以下是使用Python实现将中国近十年春节档电影的导演和演员数据写入csv文件的示例代码: ```python import csv # 电影数据 films = [ {'year':2011, 'name':'唐山大地震', 'director':'冯小刚', 'cast':'陈道明、张子枫等'}, {'year':2012, 'name':'全民目击', 'director':'陈凯歌', 'cast':'舒淇、陈建斌等'}, {'year':2013, 'name':'西游·降魔篇', 'director':'周星驰', 'cast':'舒淇、黄渤、吴亦凡等'}, {'year':2014, 'name':'人再囧途之泰囧', 'director':'徐峥', 'cast':'徐峥、王宝强等'}, {'year':2015, 'name':'捉妖记', 'director':'许诚毅', 'cast':'白百何、井柏然等'}, {'year':2016, 'name':'美人鱼', 'director':'周星驰', 'cast':'邓超、林允等'}, {'year':2017, 'name':'功夫瑜伽', 'director':'唐季礼', 'cast':'成龙、张艺兴等'}, {'year':2018, 'name':'唐人街探案2', 'director':'陈思诚', 'cast':'王宝强、刘昊然等'}, {'year':2019, 'name':'疯狂的外星人', 'director':'宁浩', 'cast':'黄渤、沈腾等'}, {'year':2020, 'name':'囧妈', 'director':'管虎', 'cast':'闫妮、赵本山等'}, {'year':2021, 'name':'唐人街探案3', 'director':'陈思诚', 'cast':'王宝强、刘昊然等'}, {'year':2012, 'name':'建国大业', 'director':'陈凯歌', 'cast':'刘劲、张丰毅等'}, {'year':2013, 'name':'失恋33天', 'director':'鲍尔吉', 'cast':'郭采洁、陈思成等'}, {'year':2014, 'name':'夏洛特烦恼', 'director':'彭大魔', 'cast':'沈腾、马丽等'}, {'year':2015, 'name':'夏目友人帐', 'director':'大森贵弘', 'cast':'神木隆之介、広瀬すず等'}, {'year':2016, 'name':'湄公河行动', 'director':'林超贤', 'cast':'张涵予、彭于晏等'}, {'year':2017, 'name':'大闹天竺', 'director':'王宝强', 'cast':'王宝强、白百何等'}, {'year':2018, 'name':'红海行动', 'director':'林超贤', 'cast':'张译、黄景瑜等'}, {'year':2019, 'name':'疯狂的外星人', 'director':'宁浩', 'cast':'黄渤、沈腾等'}, {'year':2020, 'name':'少年的你', 'director':'曾国祥', 'cast':'周冬雨、易烊千玺等'}, ] # 写入csv文件 with open('films.csv', 'w', newline='', encoding='utf-8') as csvfile: fieldnames = ['year', 'name', 'director', 'cast'] writer = csv.DictWriter(csvfile, fieldnames=fieldnames) writer.writeheader() for film in films: writer.writerow(film) ``` 运行以上代码后,将生成一个名为`films.csv`的文件,内容为导演和演员数据的表格形式。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值