Skip to content

Instantly share code, notes, and snippets.

@lxfly2000
Last active August 4, 2018 09:21
Show Gist options
  • Save lxfly2000/67ac8d133ad972cd9f6192bff507fadb to your computer and use it in GitHub Desktop.
Save lxfly2000/67ac8d133ad972cd9f6192bff507fadb to your computer and use it in GitHub Desktop.
B站下架了哪些番?
#coding:utf-8
#Python 3.6, 3.7
#该脚本目前需要配合AnimeSchedule一起使用。(https://github.com/lxfly2000/AnimeSchedule)
import json
import urllib.request
#测试有效性,成功返回1,失败返回0,非B站网页返回2
def testBilibiliURL(title,src_url):
print(title+"...",end="")
#先检查是不是B站的URL
if not "bili" in src_url.lower():
print("Error:N/A")
return
#测试链接是否返回200
try:
http_return=urllib.request.urlopen(src_url,timeout=10)
if http_return.status==200:
print("OK")
except urllib.error.HTTPError as http_e:
print("HTTPError:",http_e.msg,", Return:",http_e.code)
except urllib.error.URLError as url_e:
print("URLError:",url_e)
jsonFile=open("anime.js",encoding="utf-8")
try:
jsonStr=jsonFile.read()
finally:
jsonFile.close()
jsonObject=json.loads(jsonStr[jsonStr.find("(")+1:jsonStr.rfind(")")])
for animeObj in jsonObject["anime"]:
if animeObj["cover"]=="":
print(animeObj["title"]+" 未指定URL。")
else:
testBilibiliURL(animeObj["title"],animeObj["watch_url"])
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment