最近收集了一些隨機圖片網址,想把這些圖片全部抓取下來,到網上搜了搜,都只有抓取鏈接的,沒有抓取圖片的,這時正好看到了VariousArtist的抓圖自動機,趕緊下了個Python(我是C++黨)來試試,結果發現……
這份代碼實在是太!雞!肋!了!,運行一次只能抓一張圖片,如果靠人工點的話豈不是要點到地老天荒,于是,我編寫了一個.bat程序和一個C++程序,用來配合那份Python代碼,一次抓取多張圖片。
具體步驟如下:
1.配置好Python和C++廢話!
2.在E盤中新建一個文件夾Photo(也可以不放在E盤里,但是后面需要根據自己存放Photo文件夾的位置稍微改變一下(建議放在空間大的磁盤里,不然抓取圖片抓到一半內存不夠就尷尬了))
python為什么叫爬蟲?3.在Photo文件夾里新建一個photo.txt文件,在里面寫上如下代碼:
from urllib import request
import os
import time
import hashlib
linkn = 'https://api.3ewl.cc/acg/img.php'
python 網頁抓取?path = os.getcwd()
print ('Current Work Path is:',path)
ftcnt = 0
def filecount():
filecount = int(os.popen('dir /B |find /V /C ""').read())
return (filecount)
python api、def md5sum(filename):
f = open(filename, 'rb')
md5 = hashlib.md5()
while True:
fb = f.read(8096)
if not fb:
django api,break
md5.update(fb)
f.close()
return (md5.hexdigest())
def delfile():
all_md5 = {}
python json。filedir = os.walk(os.getcwd())
for i in filedir:
for tlie in i[2]:
if md5sum(tlie) in all_md5.values():
os.remove(tlie)
else:
python和java?all_md5[tlie] = md5sum(tlie)
oldf = 0
while True:
if (oldf + ftcnt) % 100 == 0:
print('Cleaning Double Files.')
oldf = filecount()
python爬蟲教程,print(oldf, 'Files Before Removal.')
delfile()
print(filecount(), 'Files After Removal.')
print('Deleted ', oldf - filecount(), 'Files.')
oldf = filecount()
ftcnt = ftcnt + 1
python怎么用?if ftcnt % 40 == 0:
print('Fetching',ftcnt,'th Picture from ',linkn,'...')
request.urlretrieve(linkn,path + '\\' + str(time.time()) + '.jpg')
其中第五行的https://api.3ewl.cc/acg/img.php是一個隨機圖片鏈接,可以替換為其他的隨機圖片鏈接。
編寫好之后,將這個文件重命名為photo.pyw。
4.在Photo文件夾里新建一個文件bat.txt,在里面寫下如下代碼:
python api文檔、start E:\Photo\photo.pyw
(如果你的Photo文件夾沒放在E盤里,請自行修改代碼!)
編寫好之后,將這個文件重命名為bat.bat。
5.在Photo文件夾里新建一個文件cpp.cpp,在里面寫下如下代碼:
#include
#include
Python爬取圖片,using namespace std;
int main()
{
int t;
cout<
cin>>t;
python api接口開發、for(int i=1;i<=t;i++)
system("cmd.exe /c \"E:\\Photo\\bat.bat\"");
return 0;
}
(如果你的Photo文件夾沒放在E盤里,請自行修改代碼system("cmd.exe /c \"E:\\Photo\\bat.bat\"");!)
編寫好之后,編譯運行這個C++代碼,然后會提示你輸入次數,輸入后回車確定,接下來就是耐心等待程序運行完畢,圖片就抓取完成啦!
python參考手冊?程序運行完畢后,打開Photo文件夾,你就會發現,有許多圖片靜靜地躺在這個文件夾里啦!
(因為這個程序有去重功能,所以抓取的越多越慢,建議一次抓取\(100\)~\(300\)次左右,當然,如果你家電腦配置足夠好,那都隨便啦!)
最后附上我收集的隨機圖片網址:
https://acg.toubiec.cn/random
http://jump2.bdimg.com/safecheck/index?url=rN3wPs8te/pL4AOY0zAwhwPDt1WAsCMMTkZGmy7i0bP6XsqIg2Wl6PHQ2HhF3NZelyIdz9v+qXV+GAYqxfjnDPXCnfW1ESuj6A3tY9na+QlFB65G9e67GL0F1G10srGPylUecCg3xQhV92TAmoWV0zA8Zu4mdgY0
http://www.dmoe.cc/random.php
隨機圖片api?http://api.apizz.cn/ecyt/api.php
https://yesos.cn/api/acgurl.php
https://api.wuzuhua.cn/dm
https://acg.yanwz.cn/acg.php
https://acg.yanwz.cn/menhera/api.php
https://acg.yanwz.cn/api.php
python讀取圖片數據。https://www.xiaobaibk.com/api/acg
https://www.niubai.net/yanshi/acgapi/acg.php
http://api.mtyqx.cn/api/random.php
http://api.mtyqx.cn/tapi/random.php
https://www.xwboke.cn/api/api.php
https://yun.iqinxiu.com/moe/a/
python爬取圖片代碼,https://yun.iqinxiu.com/moe/b/
https://yun.iqinxiu.com/moe/c/
https://yun.iqinxiu.com/moe/d/
版权声明:本站所有资料均为网友推荐收集整理而来,仅供学习和研究交流使用。
工作时间:8:00-18:00
客服电话
电子邮件
admin@qq.com
扫码二维码
获取最新动态