博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
使用GitHub作Free图床
阅读量:4353 次
发布时间:2019-06-07

本文共 2035 字,大约阅读时间需要 6 分钟。

一、方法原理

  1、使用GitHub的Issues问题功能。

  新建一个Issues问题请求

  将图片拖拉或者上传到问题框后,会返回一个地址,这个地址就是图片直链

  

  2、通过访问github仓库内的图片地址并进行修改

例如我的image-host仓库,地址是:https://github.com/wangchuanli001/image-host/tree/master/imgtemp

对于对应的图片,例如,

https://github.com/wangchuanli001/image-host/blob/master/imgtemp/snowtree.jpg(原地址)

进行更改后(可以作为直链访问):

https://github.com/wangchuanli001/image-host/blob/master/imgtemp/snowtree.jpg?raw=true

https://github.com/wangchuanli001/image-host/raw/master/imgtemp/snowtree.jpg

 

 二、拓展

  对于图片的上传只要记录下上传的文件路径以及文件名,就可以免费使用github作为图床使用了。

   1、通过爬虫进行爬取github上的内容,进行截取和拼接形成图片直链

    这个Python爬虫有编码问题,即gbk编码问题

import reimport urllib.requestfrom bs4 import BeautifulSoupurl = "https://github.com/wangchuanli001/image-host/tree/master/imgtemp"def getdoc():    html_doc = urllib.request.urlopen(url).read()    f = open("doc.txt","wb")    f.write(html_doc)    f.close()def test():    f = open("doc.txt","rb+")    s = f.read()    soup = BeautifulSoup(s,"html.parser",from_encoding="GB18030")    print ("start")    links = soup.select('a')    for link in links:        print (link)    f.close()

  2、通过图片上传工具进行记录

    记录本地文件路径和文件名,上传后生成直链。

import os# 从本地clone的仓库中得到文件列表def fileListFunc(fileList,filePath,suffix):    for filename in os.listdir(filePath):        if os.path.isdir((filePath+"/"+filename)):            # print (filePath+"/"+filename)            fileListFunc(fileList,(filePath+"/"+filename),suffix)        else:            if filename.endswith(suffix):                fileList.append(filePath+"/"+filename)    return fileList# 对列表中的文件进行字符串拼接成图片链接def listHandler(fileList,filePath):    for i in range(0,len(fileList)):        fileList[i] = ""    fileList.append("-----------------------")# 将图片链接追加到md文件的最后def list2md(fileList):    fo = open("image.md","a+")    for item in fileList:        fo.write(item)    fo.close()fileList = []filePath = "E:\GitHub\Respositories\image-host"fileLists = fileListFunc(fileList,filePath,"jpg")listHandler(fileLists,filePath)print (fileLists)list2md(fileLists)

 

转载于:https://www.cnblogs.com/null-/p/10051036.html

你可能感兴趣的文章
修改vs2013中MFC项目名称
查看>>
GDKOI2018发烧记
查看>>
Web API-路由(二)
查看>>
一些被忽略掉的面试题
查看>>
《大道至简》第三章读后感
查看>>
JavaScript中的ActiveXObject对象
查看>>
关于js foreach map
查看>>
ngRoute (angular-route.js) 和 ui-router (angular-ui-router.js) 模块有什么不同呢?
查看>>
Python--字典操作
查看>>
工作日志2014-07-16
查看>>
extjs_06_grid(列锁定&列分组)
查看>>
新版本号的tlplayer for android ,TigerLeapMC for windows公布了
查看>>
scrapy 爬取当当网产品分类
查看>>
第一周学习进度条
查看>>
【C++】reference parameter-引用参数
查看>>
C# 编写ActiveX
查看>>
NSValue的valueWithBytes:objCType:方法
查看>>
RasAPI函数实现PPPOE拨号
查看>>
Lowest Bit(虽然很简单)
查看>>
Git详细教程(2)---多人协作开发
查看>>