源码:
{"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)
输出结果:
如上图左边文件夹中的图片