如果不在bash或python中下载javascript文件,我如何检查该文件是否存在



如果不在bash或python 中下载javascript文件,我如何检查该文件是否存在

您可以使用python-urllib模块来检查给定URL中是否存在文件。这是一个示例代码。结果保存在";结果";词典

from urllib.request import urlopen
urls = ['https://www.codecademy.com/cdn-cgi/challenge- platform/h/g/scripts/alpha/invisible.js','https://www.codecademy.com/idontexist.js']
results={}
for url in urls:
try:
ret = urlopen(url)
if ret.code == 200:
state="Exists"
print(url+' : {}'.format(state))
except:
state="Not exists"
print(url+' : {}'.format(state))
results[url]=state

最新更新