下面是python代码。需要BeautifulSoup库。
import os
import multiprocessing
import requests
from bs4 import BeautifulSoup
stave_url="http://everyonepiano.com/Stave-{0}.html"
def main():
text=input("Please input the ID of the music, or the url of the music's home page:\n")
try:
id=int(text)
except:
id=int(text.split('-')[1])
r=requests.get(stave_url.format(id))
soup=BeautifulSoup(r.text,"lxml")
name=soup.find("div",id="musicTitle").text # Name of the music
print("Downloading stave files of: " + name+"...\n")
if not os.path.exists(name):
os.mkdir(name)
pool = multiprocessing.Pool(10) # Multi processing pool
num=1
for li in soup.find("ul",id="ul1").find_all("li"):
url = "http://everyonepiano.com" + li.img.attrs["src"]
pool.apply_async(download, (url, name+"/{0}.png".format(num)))
num+=1
pool.close() # Stop accepting new requests
pool.join() # Wait until all tasks are finished
print("Task finished! {0} file(s) saved.\n".format(num-1))
def download(url, path):
img=requests.get(url)
with open(path,"wb") as file:
file.write(img.content)
print("Downloaded image at: " + url)
if __name__ == "__main__":
main()
os.system("pause")
输入要下载的音乐的id或者网址链接,按回车开始下载。如果要下载简谱的话,把代码里的"Stave"改成"Number"就可以了。