欢迎大家查看呆呆的源码
可以爬取各种图片
废话不多说步入正题
1.下载python,在(https://python.org/) 就可以下载然后安装
2.导入requests库(不然会报错)下载tar包(https://pypi.org/project/pip)
3.把文件解压放到python安装目录lib中
4.打开cmd,运行命令pip install requests,静静等待,几秒后会成功
5.接下来可以双击运行啦(可以更改api,写注释了)
自建api:api.anbq1223.com
# -*- coding: utf-8 -*
import requests
import time
import datetime;
import random;
a = int(input('爬取张数:'))
b=1
while b <= a:
for i in range (0,1):
nowTime=datetime.datetime.now().strftime("%Y%m%d%H%M%S");#生成当前时间
randomNum=random.randint(0,100);#生成的随机整数n,其中0<=n<=100
if randomNum<=10:
randomNum=str(0)+str(randomNum);
uniqueNum=str(nowTime)+str(randomNum);
c=int(uniqueNum)
time.sleep(3) #设置延时秒数
print('正在爬取第%d张'%b)
img_url = 'https://api.vvhan.com/api/acgimg' #填写要爬取的图片api
response=requests.get(img_url)
with open('img/%d.jpg'%c,'wb') as f: #存储到img路径下
f.write(response.content)
print('第%d张爬取成功'%b)
b=b+1
print('爬取完成')
© 版权声明
THE END
暂无评论内容