Python下载酷狗音乐歌曲

最近想研究一下Python的图形界面,但是因为我的Python版本是2.7,没法用QT,所以试了试wxPython。效果还不错,虽然总体来说不如WPF好用和美观,但是做简单的应用程序足够了。

作为练习,写了一个酷狗的音乐下载器,上代码:

# -*- coding:utf8 -*-

import wx
import urllib

class App(wx.App):
    def OnInit(self):
        frame = wx.Frame(parent = None, title = 'MusicDownloader', pos = (1000, 200), size = (600, 150))
        pathTitle = wx.StaticText(frame, label = "Url链接", pos = (5,8), size = (70, 24) )
        pathText = wx.TextCtrl(frame ,pos = (70, 5), size = (400, 24))
        openButton = wx.Button(frame, label = "下载歌曲", pos=(470, 5), size=(100, 24))
        musicTitle = wx.StaticText(frame, label = "保存歌曲名", pos = (5,43), size = (70, 24))
        musicText = wx.TextCtrl(frame, pos=(70, 40), size=(300, 24))
        tipsTitle = wx.StaticText(frame, label="默认保存在桌面", pos=(5, 80), size=(100, 24))
        tipsTitle.SetForegroundColour('gray')
        def OnClickDownloadBtn(event):
            url = pathText.GetValue()
            urllib.urlretrieve(url, 'C:/Users/Administrator/Desktop/' + musicText.GetValue() + '.mp3')
        openButton.Bind(wx.EVT_BUTTON, OnClickDownloadBtn)
        frame.Show()
        return True

app = App()
app.MainLoop()

代码运行以后,界面如下:

至于用法呢,我们打开酷狗音乐主页,然后搜索想听的歌曲,进入歌曲试听界面,如下图:

我们点击右键,选择,查看元素:

然后可以看到页面源代码:

找到标签为audio的一行,复制下来:

然后,把我们所需要的src链接,复制到我们软件窗口的url链接文本框,

在保存歌曲名文本框,输入想保存的歌曲名称,最后点击下载歌曲按钮,歌曲就下载下来了:

猜你喜欢

转载自blog.csdn.net/OneWord233/article/details/89100968