用Itchat 下载朋友圈的图片 用python代码写出来
时间: 2024-02-18 14:03:22 浏览: 31
下面是使用itchat下载朋友圈图片的Python代码:
```python
import os
import itchat
# 创建一个文件夹用于存储图片
if not os.path.exists('朋友圈图片'):
os.mkdir('朋友圈图片')
# 登录微信
itchat.auto_login(hotReload=True)
# 获取自己的朋友圈
friends = itchat.get_friends(update=True)
# 遍历每个朋友的朋友圈
for friend in friends:
moments = itchat.get_moments(userName=friend['UserName'])
for moment in moments:
# 如果这条朋友圈有图片
if moment['Type'] == 3:
# 遍历每张图片
for pic in moment['Images']:
# 下载图片
img = itchat.get_msg_img(pic['MsgId'])
# 保存图片
with open('朋友圈图片/{}.jpg'.format(pic['MsgId']), 'wb') as f:
f.write(img)
```
需要注意的是,这段代码只能下载自己的朋友圈图片,无法下载其他人的朋友圈图片。另外,下载的图片将会保存在当前目录下的“朋友圈图片”文件夹中。
相关推荐
![pdf](https://img-home.csdnimg.cn/images/20210720083512.png)
![pdf](https://img-home.csdnimg.cn/images/20210720083512.png)
![rar](https://img-home.csdnimg.cn/images/20210720083606.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)