直接貼代碼
import requests
def getHeaders(url):
h = requests.head(url)
header = h.headers
locationUrl = header.get('Location')
if locationUrl:
print('重定向:',locationUrl)
h = requests.head(locationUrl)
header = h.headers
return header
def checkDownloadable(url):
header=getHeaders(url)
print(header)
contentType = header.get('content-type').lower()
# content-type: application/vnd.android.package-archive為app下載地址
if 'text' in contentType or 'html' in contentType:
return False
else:
return True
if __name__ == '__main__':
jd = 'https://imtt.dd.qq.com/sjy.20002/sjy.00004/16891/apk/B81EE60F774C63F78D58E4062EF08901.apk'
jd2='https://imtt.dd.qq.com/sjy.20002/sjy.00004/16891/apk/D684D9F9B4AF23F1432911286359A262.apk'
mm = 'https://imtt.dd.qq.com/sjy.00006/sjy.00004/16891/apk/1E0A36A8819E9B5792D4F21C8DFEE99C.apk'
mm2='https://a17.app.qq.com/o/simple.jsp?pkgname=com.immomo.momo&g_f=1185402&fromcase=70052#'
res=checkDownloadable(jd2)
print(res)