当前位置: 首页 > news >正文

Python爬虫:一个爬取豆瓣电影人像的小案例

从谷歌浏览器的开发工具进入
选择图片右键点击检查在这里插入图片描述

![在这里插入图片描述](https://img-blog.csdnimg.cn/1b38c2a942c441fb8cb545a28bb35015.png在这里插入图片描述

翻页之后发现网址变化的只有start数值,每次变化值为30

Python代码

import requests
from bs4 import BeautifulSoup
import time
import os# 豆瓣影人图片
url = 'https://movie.douban.com/celebrity/1011562/photos/'
res = requests.get(url=url, headers="").text
content = BeautifulSoup(res, "html.parser")
data = content.find_all('div', attrs={'class': 'cover'})
picture_list = []
for d in data:plist = d.find('img')['src']picture_list.append(plist)
print(picture_list)# https://movie.douban.com/celebrity/1011562/photos/?type=C&start=30&sortby=like&size=a&subtype=a
def get_poster_url(res):content = BeautifulSoup(res, "html.parser")data = content.find_all('div', attrs={'class': 'cover'})picture_list = []for d in data:plist = d.find('img')['src']picture_list.append(plist)return picture_list# XPath://*[@id="content"]/div/div[1]/ul/li[1]/div[1]/a/img
def download_picture(pic_l):if not os.path.exists(r'picture'):os.mkdir(r'picture')for i in pic_l:pic = requests.get(i)p_name = i.split('/')[7]with open('picture\\' + p_name, 'wb') as f:f.write(pic.content)def fire():page = 0for i in range(0, 450, 30):print("开始爬取第 %s 页" % page)url = 'https://movie.douban.com/celebrity/1011562/photos/?type=C&start={}&sortby=like&size=a&subtype=a'.format(i)res = requests.get(url=url, headers="").textdata = get_poster_url(res)download_picture(data)page += 1time.sleep(1)fire()

在这里插入图片描述

把爬取的图片全部放到新建的文件夹中存放
在这里插入图片描述

http://www.lryc.cn/news/147408.html

相关文章:

  • STM32CubeMX配置STM32G0 Standby模式停止IWDG(HAL库开发)
  • 39.RESTful案例
  • Power Pivot 实现数据建模
  • Ansible自动化运维之playbooks剧本
  • Docker - Docker安装MySql并启动
  • SQL Server 2019导入txt数据
  • 科研 | Zotero导入无PDF的参考文献、书籍
  • 【Docker】docker入门之dockerfile编写
  • javaee之黑马乐优商城1
  • 滴滴前端一面面经(已挂)
  • 靠谱的适合上班族做的副业,这几种一定要试试!
  • VSCode连接服务器
  • Python爬虫网络安全:优劣势和适用范围分析
  • swift APP缓存
  • Linux中的dpkg指令(dpkg -l | grep XXX等)
  • import type {} from ‘module‘ 具体解释
  • 十年JAVA搬砖路——数据结构线性结构
  • Mybatis为什么需要预编译等一系列问题
  • 【JVM基础】JVM入门基础
  • 【SpringBoot】详细介绍Spring Boot中@Component
  • Redis执行lua脚本-Time函数-获取当前时间
  • 前端无需install快速调试npm包,Console-Import使用
  • 构建稳定的爬虫系统:如何选择合适的HTTP代理服务商
  • Python爬虫基础:使用Scrapy库初步探索
  • MacBookPro重装系统图文教程
  • Android 6.0长按电源键添加重启菜单
  • Python股票交易---均值回归
  • 机器人制作开源方案 | 桌面级机械臂--本体说明+驱动及控制
  • 有哪些前端调试和测试工具? - 易智编译EaseEditing
  • 【数据结构】手撕单链表