一、復(fù)制歌曲鏈接
二、F12啟動(dòng)開(kāi)發(fā)者工具找到音頻標(biāo)簽查看src屬性
三、復(fù)制src屬性進(jìn)行搜索進(jìn)行查看發(fā)現(xiàn)時(shí)音頻文件
四、了解流程開(kāi)始編寫(xiě)程序
代碼:
import requests
from selenium import webdriver
import time
from lxml import etree
from fake_useragent import UserAgent
import os
from selenium.webdriver.chrome.options import Options
def music_parse():
if not os.path.exists('./音樂(lè)'):
os.mkdir("音樂(lè)")
url=input('請(qǐng)輸入歌曲地址')
wb=webdriver.Chrome(executable_path="./chromedriver.exe",options=chrome_options)
wb.get(url=url)
data=wb.page_source
wb.quit()
tree=etree.HTML(data)
music=tree.xpath('//*[@class="music"]/@src')[0]
musicname="./音樂(lè)/"+tree.xpath('//*[@class="audioName"]/@title')[0]+".mp3"
return music,musicname
def music_download(music,musicname):
response=requests.get(url=music,headers=headers).content
with open(musicname,"wb")as fp:
fp.write(response)
print("下載完成")
if __name__ == '__main__':
chrome_options = Options()
chrome_options.add_argument('--headless')
chrome_options.add_argument('--disable-gpu')
headers={"User-Agent":UserAgent().random}
music,musicname=music_parse()
music_download(music,musicname)
五、運(yùn)行結(jié)果
最后編輯于 :
?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請(qǐng)聯(lián)系作者
【社區(qū)內(nèi)容提示】社區(qū)部分內(nèi)容疑似由AI輔助生成,瀏覽時(shí)請(qǐng)結(jié)合常識(shí)與多方信息審慎甄別。
平臺(tái)聲明:文章內(nèi)容(如有圖片或視頻亦包括在內(nèi))由作者上傳并發(fā)布,文章內(nèi)容僅代表作者本人觀點(diǎn),簡(jiǎn)書(shū)系信息發(fā)布平臺(tái),僅提供信息存儲(chǔ)服務(wù)。