国产探花免费观看_亚洲丰满少妇自慰呻吟_97日韩有码在线_资源在线日韩欧美_一区二区精品毛片,辰东完美世界有声小说,欢乐颂第一季,yy玄幻小说排行榜完本

首頁 > 編程 > Python > 正文

python Selenium實(shí)現(xiàn)付費(fèi)音樂批量下載的實(shí)現(xiàn)方法

2020-02-16 00:51:35
字體:
供稿:網(wǎng)友

必備環(huán)境

廢話

每年回家都要幫我爸下些音樂,這對我來說都是輕車熟路!可當(dāng)我打開網(wǎng)易云點(diǎn)擊下載按鈕的時候,可惜已物是人非啦!

開個 VIP 其實(shí)也不貴,臨時用用也就¥15!但 IT 男的尊嚴(yán)必須要有,于是開始徜徉于搜索引擎中

最后在知乎中,搜索到一個網(wǎng)址VIP付費(fèi)音樂解析

P.S.再次感謝提供該服務(wù)的作者!如果你下載的音樂數(shù)量不多,直接這里搜索下載,下載后修改文件名即可!并且在這個網(wǎng)址中點(diǎn)擊播放列表-點(diǎn)擊同步,可以同步網(wǎng)易云的歌單!之后批量下載即是下載這些網(wǎng)易云的歌單!但是下載某個歌單中的幾百首歌,手動下載就不現(xiàn)實(shí)了!在點(diǎn)擊同步中需要輸入你的網(wǎng)易云 UID,這 UID 的獲取方式如下:第一步打開網(wǎng)易云隨便選中一首歌,右鍵復(fù)制鏈接

然后隨便找個地方粘貼這個鏈接,例如https://music.163.com/song?id=25727803&userid=275613591最后這串?dāng)?shù)字就是 UID!

程序運(yùn)行環(huán)境

第一步安裝一個python3,這個簡單吧!貼上我的版本 python3.65,安裝時注意勾選Add in path

第二步下載FFmpeg,這是用來解析視頻和音頻的,作為you-get的輔助工具,下載點(diǎn)這里,下載后解壓添加環(huán)境變量即可

第三步安裝you-get,這是個下載視頻音頻的神器,有興趣可以深入研究!之后我打算寫個下載任意視頻的工具,嘿嘿這是后話了!安裝方式很簡單pip install you-get

環(huán)境配置就這樣,還是非常輕松的,下面會解釋下代碼

源碼

完整代碼

from selenium import webdriverfrom selenium.webdriver.common.action_chains import ActionChainsimport time, os# import thredingdef get_music_name_link():  main_handle = browser.current_window_handle  fp = open('E://Project_PY//file//musiclink.txt','wb')  fp2 = open('E://Project_PY//file//musicname.txt','wb')  try:    for i in list(range(2,400)):      browser.switch_to_window(main_handle)      txt = browser.find_element_by_xpath('/html/body/div[3]/div/div[2]/div[2]/div[1]/div/div[%d]' % i).text + '/n'      fp2.write(bytes(txt,encoding='utf-8'))      location = browser.find_element_by_xpath('/html/body/div[3]/div/div[2]/div[2]/div[1]/div/div[%d]' % i)      ActionChains(browser).move_to_element(location).perform()      browser.find_element_by_xpath('/html/body/div[3]/div/div[2]/div[2]/div[1]/div/div[%d]/span[5]/div/span[2]' % i).click()      time.sleep(2)      all_handles = browser.window_handles      browser.switch_to_window(all_handles[-1]) # lastest      url_link = browser.current_url + '/n'      fp.write(bytes(url_link,encoding='utf-8'))      browser.close()  except Exception as e:    print('get_music_name_link meet some problem! {}'.format(e))    fp.close()    fp2.close()def download_music(list_name):  with open('E://Project_PY//file//musicname.txt','r',encoding='utf-8') as fp1:      music_name = fp1.readlines()  len1 = len(music_name)  fp2 = open('E://Project_PY//file//musicname_format.txt','w',encoding='utf-8')  for i in range(3,len1,4):    music_name_format = music_name[i].strip() + '/n'    fp2.write(music_name_format)  fp2.close()  with open('E://Project_PY//file//musiclink.txt','r',encoding='utf-8') as fp1:     with open('E://Project_PY//file//musicname_format.txt','r',encoding='utf-8') as fp2:       for music_link,music_name in zip(fp1.readlines(),fp2.readlines()):        you_get_link = 'you-get "{}" -o "E://Project_PY//file//music//{}" -O "{}"'.format(music_link.strip(),list_name,music_name.strip())        you_get_link = you_get_link.strip()        # print(you_get_link)        os.system(you_get_link)url = 'http://music.zhuolin.wang/'uid = input('please input your uid:')options = webdriver.FirefoxOptions()options.add_argument('--headless')browser = webdriver.Firefox(firefox_options=options)browser.implicitly_wait(8)browser.get(url)# browser.maximize_window()browser.set_window_size(1000,100000)browser.find_element_by_xpath('/html/body/div[3]/div/div[1]/div/span[3]').click()# scroll = browser.find_element_by_xpath('//*[@id="mCSB_1_dragger_vertical"]')# ActionChains(browser).drag_and_drop_by_offset(scroll,0,100).perform()# time.sleep(2)all_handles = browser.window_handlesbrowser.switch_to_window(all_handles[-1]) # lastesttime.sleep(1)browser.find_element_by_xpath('/html/body/div[3]/div/div[2]/div[1]/div[1]/div/span/div[2]/span').click()all_handles = browser.window_handlesbrowser.switch_to_window(all_handles[-1]) # lastesttime.sleep(1)browser.find_element_by_xpath('/html/body/div[6]/div[2]/input').send_keys(uid)browser.find_element_by_xpath('/html/body/div[6]/div[3]/a[1]').click()# t1 = threading.Thread(target=get_music_name)# t2 = threading.Thread(target=get_music_link)# t3 = threading.Thread(target=download_music)for i in list(range(3,100)):  try:    print('downloading song_list{}! please waiting....'.format(i))    browser.find_element_by_xpath('/html/body/div[3]/div/div[2]/div[1]/div[1]/div/div[%d]/img' % i).click()    dir_name = browser.find_element_by_xpath('/html/body/div[3]/div/div[2]/div[1]/div[1]/div/div[%d]/p' % i).text    time.sleep(1)    get_music_name_link()    download_music(dir_name)    browser.find_element_by_xpath('/html/body/div[3]/div/div[1]/div/span[3]').click()    time.sleep(1)    all_handles = browser.window_handles    browser.switch_to_window(all_handles[-1]) # lastest    time.sleep(5)  except Exception as e:    print('get_song_list meet some problem! {}'.format(e))browser.quit()            
發(fā)表評論 共有條評論
用戶名: 密碼:
驗證碼: 匿名發(fā)表
主站蜘蛛池模板: 定日县| 江永县| 盐津县| 中阳县| 资兴市| 宁城县| 漳浦县| 屯门区| 临安市| 佛山市| 鄂温| 和平区| 上犹县| 肥城市| 舞钢市| 黄平县| 高邮市| 凉城县| 信宜市| 大城县| 香港 | 即墨市| 福泉市| 泰州市| 汕头市| 双流县| 浦东新区| 习水县| 庐江县| 五峰| 玉龙| 酒泉市| 伽师县| 历史| 建湖县| 和平区| 祁连县| 罗田县| 开化县| 祥云县| 房产|