没注意Imgur被墙了,把博客上的图下载回来重传到GitHub上

因为之前用的PicGo这款软件,所以直接用Sublime Text 3写个正则(https://.*)(\.png|jpg)C:\Users\Administrator\AppData\Roaming\PicGo\data.json里提取下图片链接

1555038588204

提取后写个小脚本,直接保存到博客目录的/source/images/

1555038673442

代码如下

'''
@Description:
@Author: Sp4ce
@Github: https://github.com/NS-Sp4ce
@LastEditors: Sp4ce
@Date: 2019-04-12 09:56:07
@LastEditTime: 2019-04-12 11:12:20
'''

import requests
from random import choice

'''
USER_AGENTS 随机头信息
'''

USER_AGENTS = [
"Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1; SV1; AcooBrowser; .NET CLR 1.1.4322; .NET CLR 2.0.50727)",
"Mozilla/4.0 (compatible; MSIE 7.0; Windows NT 6.0; Acoo Browser; SLCC1; .NET CLR 2.0.50727; Media Center PC 5.0; .NET CLR 3.0.04506)",
"Mozilla/4.0 (compatible; MSIE 7.0; AOL 9.5; AOLBuild 4337.35; Windows NT 5.1; .NET CLR 1.1.4322; .NET CLR 2.0.50727)",
"Mozilla/5.0 (Windows; U; MSIE 9.0; Windows NT 9.0; en-US)",
"Mozilla/5.0 (compatible; MSIE 9.0; Windows NT 6.1; Win64; x64; Trident/5.0; .NET CLR 3.5.30729; .NET CLR 3.0.30729; .NET CLR 2.0.50727; Media Center PC 6.0)",
"Mozilla/5.0 (compatible; MSIE 8.0; Windows NT 6.0; Trident/4.0; WOW64; Trident/4.0; SLCC2; .NET CLR 2.0.50727; .NET CLR 3.5.30729; .NET CLR 3.0.30729; .NET CLR 1.0.3705; .NET CLR 1.1.4322)",
"Mozilla/4.0 (compatible; MSIE 7.0b; Windows NT 5.2; .NET CLR 1.1.4322; .NET CLR 2.0.50727; InfoPath.2; .NET CLR 3.0.04506.30)",
"Mozilla/5.0 (Windows; U; Windows NT 5.1; zh-CN) AppleWebKit/523.15 (KHTML, like Gecko, Safari/419.3) Arora/0.3 (Change: 287 c9dfb30)",
"Mozilla/5.0 (X11; U; Linux; en-US) AppleWebKit/527+ (KHTML, like Gecko, Safari/419.3) Arora/0.6",
"Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.8.1.2pre) Gecko/20070215 K-Ninja/2.1.1",
"Mozilla/5.0 (Windows; U; Windows NT 5.1; zh-CN; rv:1.9) Gecko/20080705 Firefox/3.0 Kapiko/3.0",
"Mozilla/5.0 (X11; Linux i686; U;) Gecko/20070322 Kazehakase/0.4.5",
"Mozilla/5.0 (X11; U; Linux i686; en-US; rv:1.9.0.8) Gecko Fedora/1.9.0.8-1.fc10 Kazehakase/0.5.6",
"Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/535.11 (KHTML, like Gecko) Chrome/17.0.963.56 Safari/535.11",
"Mozilla/5.0 (Macintosh; Intel Mac OS X 10_7_3) AppleWebKit/535.20 (KHTML, like Gecko) Chrome/19.0.1036.7 Safari/535.20",
"Opera/9.80 (Macintosh; Intel Mac OS X 10.6.8; U; fr) Presto/2.9.168 Version/11.52",
"Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/536.11 (KHTML, like Gecko) Chrome/20.0.1132.11 TaoBrowser/2.0 Safari/536.11",
"Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/537.1 (KHTML, like Gecko) Chrome/21.0.1180.71 Safari/537.1 LBBROWSER",
"Mozilla/5.0 (compatible; MSIE 9.0; Windows NT 6.1; WOW64; Trident/5.0; SLCC2; .NET CLR 2.0.50727; .NET CLR 3.5.30729; .NET CLR 3.0.30729; Media Center PC 6.0; .NET4.0C; .NET4.0E; LBBROWSER)",
"Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1; SV1; QQDownload 732; .NET4.0C; .NET4.0E; LBBROWSER)",
"Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/535.11 (KHTML, like Gecko) Chrome/17.0.963.84 Safari/535.11 LBBROWSER",
"Mozilla/4.0 (compatible; MSIE 7.0; Windows NT 6.1; WOW64; Trident/5.0; SLCC2; .NET CLR 2.0.50727; .NET CLR 3.5.30729; .NET CLR 3.0.30729; Media Center PC 6.0; .NET4.0C; .NET4.0E)",
"Mozilla/5.0 (compatible; MSIE 9.0; Windows NT 6.1; WOW64; Trident/5.0; SLCC2; .NET CLR 2.0.50727; .NET CLR 3.5.30729; .NET CLR 3.0.30729; Media Center PC 6.0; .NET4.0C; .NET4.0E; QQBrowser/7.0.3698.400)",
"Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1; SV1; QQDownload 732; .NET4.0C; .NET4.0E)",
"Mozilla/4.0 (compatible; MSIE 7.0; Windows NT 5.1; Trident/4.0; SV1; QQDownload 732; .NET4.0C; .NET4.0E; 360SE)",
"Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1; SV1; QQDownload 732; .NET4.0C; .NET4.0E)",
"Mozilla/4.0 (compatible; MSIE 7.0; Windows NT 6.1; WOW64; Trident/5.0; SLCC2; .NET CLR 2.0.50727; .NET CLR 3.5.30729; .NET CLR 3.0.30729; Media Center PC 6.0; .NET4.0C; .NET4.0E)",
"Mozilla/5.0 (Windows NT 5.1) AppleWebKit/537.1 (KHTML, like Gecko) Chrome/21.0.1180.89 Safari/537.1",
"Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/537.1 (KHTML, like Gecko) Chrome/21.0.1180.89 Safari/537.1",
"Mozilla/5.0 (iPad; U; CPU OS 4_2_1 like Mac OS X; zh-cn) AppleWebKit/533.17.9 (KHTML, like Gecko) Version/5.0.2 Mobile/8C148 Safari/6533.18.5",
"Mozilla/5.0 (Windows NT 6.1; Win64; x64; rv:2.0b13pre) Gecko/20110307 Firefox/4.0b13pre",
"Mozilla/5.0 (X11; Ubuntu; Linux x86_64; rv:16.0) Gecko/20100101 Firefox/16.0",
"Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/537.11 (KHTML, like Gecko) Chrome/23.0.1271.64 Safari/537.11",
"Mozilla/5.0 (X11; U; Linux x86_64; zh-CN; rv:1.9.2.10) Gecko/20100922 Ubuntu/10.10 (maverick) Firefox/3.6.10"
]
'''
要爬的图片
'''
url = ["https://i.imgur.com/kE3atnM.jpg",
"https://i.imgur.com/K0ir4GS.jpg",
"https://i.imgur.com/IGl4o0B.png",
"https://i.imgur.com/xCyyXjU.png",
"https://i.imgur.com/c245pIe.png",
"https://i.imgur.com/8P1fu00.png",
"https://i.imgur.com/iTJfqEf.png",
"https://i.imgur.com/0Y7xwUl.png",
"https://i.imgur.com/W094eVA.png",
"https://i.imgur.com/yOXYcFY.png",
"https://i.imgur.com/nSGClOf.png",
"https://i.imgur.com/SjrKLsD.png",
"https://i.imgur.com/J2a5zf3.png",
"https://i.imgur.com/kSISTKX.png",
"https://i.imgur.com/S736bs1.png",
"https://i.imgur.com/PjRWXTZ.png",
"https://i.imgur.com/yruh3Pq.png",
"https://i.imgur.com/s38MFFX.png",
"https://i.imgur.com/sPE20Hb.png",
"https://i.imgur.com/Ye7UZud.png",
"https://i.imgur.com/xMzzCZJ.png",
"https://i.imgur.com/esB7tyE.png",
"https://i.imgur.com/cvxCVx1.png",
"https://i.imgur.com/bD6y8ZP.png",
"https://i.imgur.com/4EXOh4m.png",
"https://i.imgur.com/fO5cyZG.png",
"https://i.imgur.com/DIdK6Z2.png",
"https://i.imgur.com/VlpAP9x.png",
"https://i.imgur.com/vFfnPmR.png",
"https://i.imgur.com/33OQjRC.png",
"https://i.imgur.com/tC5ULwB.png",
"https://i.imgur.com/RRpquVF.png",
"https://i.imgur.com/tqlK5nk.png",
"https://i.imgur.com/ekaoutn.png",
"https://i.imgur.com/EdUQG81.png",
"https://i.imgur.com/5wHxY18.png",
"https://i.imgur.com/o4JmAOC.png",
"https://i.imgur.com/y6oQvSz.png",
"https://i.imgur.com/NII0BB1.png",
"https://i.imgur.com/So4QQQi.png",
"https://i.imgur.com/KAqDDXX.png",
"https://i.imgur.com/IeVvnxj.png",
"https://i.imgur.com/ofCS3YD.png",
"https://i.imgur.com/jOkSclQ.png",
"https://i.imgur.com/xI2gMw7.png",
"https://i.imgur.com/LbTCSRm.png",
"https://i.imgur.com/XLntPfM.png",
"https://i.imgur.com/JtgcTUf.png",
"https://i.imgur.com/m0ZsPMQ.png",
"https://i.imgur.com/oBvtki7.png",
"https://i.imgur.com/mHkYCIg.png",
"https://i.imgur.com/z3MZ1bQ.png",
"https://i.imgur.com/z9yE9WC.png",
"https://i.imgur.com/I6kUFLf.png",
"https://i.imgur.com/XZ5CSOb.png",
"https://i.imgur.com/IwcYFcO.png",
"https://i.imgur.com/3Uu0tpL.png",
"https://i.imgur.com/rSPg1hK.png",
"https://i.imgur.com/Mn1ZkmD.png",
"https://i.imgur.com/GLCnFCF.png",
"https://i.imgur.com/5JxxULl.png",
"https://i.imgur.com/H67jYWx.png",
"https://i.imgur.com/VMs1r1r.png",
"https://i.imgur.com/MtBdViP.png",
"https://i.imgur.com/Vt2YN9X.png",
"https://i.imgur.com/Fqrmmzf.png",
"https://i.imgur.com/llan4IP.png",
"https://i.imgur.com/VUPv5h2.png",
"https://i.imgur.com/k2T81yl.png",
"https://i.imgur.com/ZNfTCeU.png",
"https://i.imgur.com/THTBupL.png",
"https://i.imgur.com/0Yb4UVs.png",
"https://i.imgur.com/fN8UQ4p.png",
"https://i.imgur.com/ft1JSYE.png",
"https://i.imgur.com/Jl5iYlS.png",
"https://i.imgur.com/fCmtfmQ.png",
"https://i.imgur.com/bgbVlHY.png",
"https://i.imgur.com/V8UFiNW.png",
"https://i.imgur.com/KEPMTDJ.png",
"https://i.imgur.com/cDK4uAr.png",
"https://i.imgur.com/tgu1VRB.png",
"https://i.imgur.com/Bgo9UZt.png",
"https://i.imgur.com/2fTNylb.png",
"https://i.imgur.com/3jGpBn8.png",
"https://i.imgur.com/aMnIsaI.png",
"https://i.imgur.com/qDqUgTU.png",
"https://i.imgur.com/t0d7dFH.png",
"https://i.imgur.com/el9mg3o.png",
"https://i.imgur.com/eKrIdl7.png",
"https://i.imgur.com/jztCtrX.png",
"https://i.imgur.com/27OOfqx.png",
"https://i.imgur.com/Xk04H89.png",
"https://i.imgur.com/TgaG9LZ.png",
"https://i.imgur.com/Wr1vQVq.png",
"https://i.imgur.com/MDlt5N1.png"]

proxies = {'http': 'socks5://127.0.0.1:1080'}
headers = {'User-Agent': choice(USER_AGENTS)}
folder_path = 'path/to/hexo/blog/source/images/' # 保存的图片目录

def getImgurPic(url):
response = requests.get(url, proxies=proxies, headers=headers)
print('[+]'+url+'----'+str(response.status_code))
saveImg(renameImg(url),response)

def renameImg(imgUrl):
imgExt = imgUrl.split('.')[-1]
imgName = imgUrl.split('.')[-2]
imgName = imgName.split('/')[-1]
img_name = folder_path + imgName + '.' + imgExt
return img_name


def saveImg(imgName,response):
with open(imgName, 'wb') as file: # 以byte形式将图片数据写入
file.write(response.content)
file.flush()
print('[+] ' + '图片:'+imgName+ ' 保存完成')

if __name__ == '__main__':
for imgUrl in url:
getImgurPic(imgUrl)

最终结果

1555038827528

搞定,替换掉md文件中的链接即可