data/method/python/例程/guitar/guitar.py

52 lines
1.5 KiB
Python

import requests
from lxml import etree
url = 'https://www.susanguitar.com/Home/Index/search'
headers = {'user-agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/99.0.4844.51 Safari/537.36'
}
name = input("请输入你想要下载的歌曲吉他谱:")
payload = {
'keyword': name
}
res = requests.post(url = url,data = payload,headers = headers)
#print(res.text)
tree = etree.HTML(res.text)
str_res = etree.tostring(tree,encoding='utf-8').decode('utf-8')
#print(str_res)
#f = open("demo.txt", "w",encoding="utf-8")
#f.write(str_res)
#f.close()
r2=tree.xpath('/html/body//div[@class="content-left"]//a[@target="_blank"]/text()')
#print(r)
i = 0
for h3 in r2:
print(i,h3)
i = i+1
a = int(input("输入你想要下载的版本:"))
r = tree.xpath('/html/body//div[@class="content-left"]//ul//a/@href')
url = "https://www.susanguitar.com"+r[a]
print(url)
respon = requests.get(url = url,headers = headers)
#print(respon.text)
tr = etree.HTML(respon.text)
strres = etree.tostring(tr,encoding='utf-8').decode('utf-8')
#print(strres)
r1 = tr.xpath('/html//div[@class="content-left-div"]//img/@src')
import os
path = './gutar/'+name+'/'+r2[a]
isExists = os.path.exists(path)
if not isExists:
os.makedirs(path)
z = 1
for h in r1:
print(h)
load = requests.get(url = h,headers = headers)
srcfile = open(path+'/'+r2[a]+str(z)+'.jpg','wb')
srcfile.write(load.content)
srcfile.close()
z = z+1