In recent days, learning a bit of python, for the crawler is more interested in, made a simple crawler project, using Python's library Tkinsert to do an interface, I feel that this library is still quite convenient to use, the music data from NetEase cloud music an interface, through the requests module, get request will be the data to obtain, the use of Json Json module for data parsing, and finally use python's mp3play library to play music online, the following is the source code of the program.
#!/usr/bin/env python # -*- coding: utf-8 -*- # @Date : 2016-12-28 21:03:21 # @Author : Donoy (172829352@) # @Link : /Donoy/ # @Version : $Id$ from Tkinter import * import tkMessageBox import requests import json import urllib import mp3play import threading import time def center_window(root, width, height): screenwidth = root.winfo_screenwidth() screenheight = root.winfo_screenheight() size = '%dx%d+%d+%d' % (width, height, (screenwidth - width)/2, (screenheight - height)/2) (size) def createWnd(): global root global listBox global text root = Tk() ('-----DMPlayer------ from Netflix -----') center_window(root, 440, 250) root['background'] = '#C7EDCC' text = Entry(font='Song Style',width=36) () button = Button(root,text='Search',width=18,fg='red',background='#CDCDC1',command=searchM).pack() listBox = Listbox(root, height=12,width=72,background='#C7EDCC') ('<Double-Button-1>',play) () () def searchM(): global m_List itemCount = 50 if not (): ('Warm Tips','You can search by entering the following \n1.song title\n2.artist name\n3.part of the lyrics') return #Get the input song title url = './search/get/?type=1&s=%s&limit=%s'%((),itemCount) #get request header = {'User-Agent':'Mozilla/5.0 (Windows NT 6.3; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/55.0.2883.75 Safari/537.36'} html = (url,header) data = () m_List = [] try: (0,()) for MusicData in data['result']['songs']: (END,MusicData['name'] +'------'+'(' +MusicData['artists'][0]['name'] + ')') m_List.append(MusicData['audio']) except Exception as e: ('Warm Tips','There was an error in the query process, please try again') #print 'There was an error in the query process, please try again' def play(args): try: global mp3 sy = ()[0] mp3 = (m_List[int(sy)]) () #(1000) except Exception as e: pass def main(): createWnd() if __name__ == '__main__': main()
Program run results:
This is the whole content of this article.