当前位置:   article > 正文

【Python爬虫项目】酷狗音乐附源码_python爬取酷狗付费音乐

python爬取酷狗付费音乐

一、复制歌曲链接

二、F12启动开发者工具找到音频标签查看src属性

三、复制src属性进行搜索进行查看发现时音频文件

四、了解流程开始编写程序

代码:

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('./音乐'):
        os.mkdir("音乐")
    url=input('请输入歌曲地址')
    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="./音乐/"+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)
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13
  • 14
  • 15
  • 16
  • 17
  • 18
  • 19
  • 20
  • 21
  • 22
  • 23
  • 24
  • 25
  • 26
  • 27
  • 28
  • 29
  • 30
  • 31

五、运行结果


声明:本文内容由网友自发贡献,不代表【wpsshop博客】立场,版权归原作者所有,本站不承担相应法律责任。如您发现有侵权的内容,请联系我们。转载请注明出处:https://www.wpsshop.cn/w/小舞很执着/article/detail/862578
推荐阅读
相关标签
  

闽ICP备14008679号