Today, my colleagues are also doing the development of wechat applets , Need music interface test , But it's troublesome to use Netease cloud's open interface , And you can't test it , I also told you about it here , So I wrote a simple Netease cloud song with crawler URL The reptiles of , Store data in mysql database , recycling django The package contains a simple API Interface , Test for colleagues .


establish django project , Do a good job of basic configuration , stay views There are two ways in writing , One is from mysql Look up the data in the database and encapsulate it into API, One is the crawler method , After the data is picked up , adopt django Of ORM Insert data into mysql In the database .

The route here also corresponds to two , One is the crawler's request routing ( It's running the route ), One is interface routing ,MODEL It's also for convenience , Just set up two fields , One is the name of the song , One is URL Address .

The code is as follows

views File code

from django.shortcuts import render,HttpResponse
import requests
from lxml import etree
from .models import Api
# Create your views here.
def api_wy(request):
api = Api.objects.all()
return render(request, "index.html",locals()) def pc(request):
url = ''
headers = {
'user-agent': 'Mozilla/5.0 (Windows NT 10.0; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/70.0.3538.25 Safari/537.36 Core/1.70.3861.400 QQBrowser/10.7.4313.400'
data = requests.get(url=url, headers=headers)
html = etree.HTML(data.text)
music_list = html.xpath('//ul[@class="f-hide"]/li/a') music_lis = [] # Store song information
for music in music_list:
music_name = music.xpath('./text()')[0] # Get the song name
music_id_all = music.xpath('./@href')[0] # obtain a Label content
music_id = music_id_all.split('=')[-1] # take a Label content for data cleaning , Extract the content of the song id
download_music = music_name + ' ' + f'{music_id}.mp3' # Name the song and url Splicing
print(download_music) for url in music_lis:
url_name = url.split(' ')[0] # Get the name
url_music = url.split(' ')[1] # obtain url
print(" Inserting data ")
return HttpResponse(" Downloading ")

URL Routing file

from django.contrib import admin
from django.urls import path
from api.views import api_wy,pc urlpatterns = [

Models level

from django.db import models
# Create your models here.
class Api(models.Model):
name = models.CharField(' Song name ', max_length=100)
url = models.CharField(" Song address ",max_length=300) class Meta:
verbose_name = ' song API'
verbose_name_plural = verbose_name def __str__(self):

There's nothing else to say , It's also a relatively simple test requirement , Just to save something

Okay , That's it today , Bye-bye

Reptiles +django, Personalize API More articles on interfaces

  1. Spring Boot Introductory series ( twenty ) Fast build Restful API Interface

    spring boot This is the 20th article in the introductory series , We talked about it earlier spring boot The basic content of the introduction , Also introduced spring boot Integrate mybatis, Integrate redis. Integrate Thymeleaf Templates ...

  2. Django FBV CBV And the use of django Provided API Interface

    FBV and CBV Either way is OK , Choose according to your own situation have a look FBV Code for URL Writing : from django.conf.urls import url from api import v ...

  3. Python use Django Write restful api Interface

    use Python How to write an interface , First of all, there must be data , We can use the data we crawled on the website , In the last article, I wrote how to use Python Reptiles , You can have a look if you are interested : ...

  4. Django Use AJAX Call your own API Interface

    Django Use AJAX Call your own API Interface *** The specific code and data have been uploaded to github ...

  5. Python Distributed crawler to create a full version of the search engine - be based on Scrapy、Redis、elasticsearch and django Build a complete search engine website

    Python Distributed crawlers build search engines be based on Scrapy.Redis.elasticsearch and django Build a complete search engine website ...

  6. First time to know Django —Python API Introduction to interface programming

    First time to know Django —Python API Introduction to interface programming One .WEB A brief introduction to the architecture Django What is it? ? Django Is an open source Web Application framework , from Python It's written in . Our goal is to use Python Language , ...

  7. Python Multi thread Douban film review API Interface crawler

    The reptile library Easy to use requests library , This is a blocked Library , Relatively slow . Parsing uses XPATH expression In general, it takes the form of class Multithreading Use concurrent.future Concurrent modules , Set up thread pool , hold future object ...

  8. About Netease cloud music crawler api Interface ?

    The ability to grab bags is limited , This paper analyzes some features of Netease cloud music api Interface , But a lot about it post The requests are encrypted , I didn't quite understand . I saw a tutorial written by a Douban Engineer in Zhihu before , But it was deleted by the complaint , There are netizens fork Did you get it ? Because I think he ...

  9. API Interface access frequency limit / Website malicious crawler restrictions / Website malicious access restrictions programme

    API Interface access frequency limit / Website malicious crawler restrictions / Website malicious access restrictions programme Adopt multi-level interception , The way of post interception is systematized 1 Layered interception 1.1 first floor business web Application firewall (WAF) Direct use of business services Conventional F ...

  10. Django project :CMDB( Server hardware assets automatic collection system )--03--03CMDB Information security API Interface interaction Authentication """ Django settings for AutoCmdb project. Generated by 'django-admin sta ...

Random recommendation

  1. [Modern OpenGL series ( One )] Ten steps OpenGL development environment

    This article has been published in CSDN: OpenGL Official website :https://www.opengl.or ...

  2. Form verification and PC Differences in ends

    1. Mobile terminal : Due to the limitation of small pages , Form validation is done from top to bottom , If the last validation fails , Error prompt is given , In the code return Go back , You don't have to do the next check : 2.PC End : The page is wide , Usually at the back or bottom of the form , Tips ...

  3. golang Threads and channels

    First, let's look at threads , stay golang It's also called goroutine Before reading this article , We need to understand concurrency and parallelism .golang Thread is a concurrency mechanism , Not in parallel . The difference between them can be searched on the Internet , There are many introductions on the Internet ...

  4. take excel Split into multiple files according to a column ( Scheme arrangement )

    1 Solution : take excel Split into multiple files according to a column 2 Problems encountered : solve vbe6ext.olb You can't ...

  5. Luogu5155 [USACO18DEC]Balance Beam

    Topic link : Luogu This question seems to be an expectation question , But it's actually a computational geometry ( This kind of question is wonderful ) First of all, there is a good conclusion , At a length of $L$ On the number axis of , Each time from $x$ Starting from , Keep walking , Yes $\frac{x}{L}$ From the right side ...

  6. mySQL Simple operation ( 3、 ... and )

    1. Business (1)ACID Atomicity ( Indivisibility )automicity Uniformity consistency Isolation, isolation persistence durability (2) Transaction control statement begin/start ...

  7. Why? web3 1.0 The interface is personal_* and eth_* Of , What's the difference between the two

    see Why personal_* namespace instead of eth_* namespace? I be ...

  8. avi Video format to yuv Format and play yuv video

    Because we need to use it yuv Format video . And now there's just avi Video format , So we need to switch , and opencv I won't support it yuv Encoded video playback . So it needs to be converted to rgb code . And then play . I wrote two programs . For reference : 1,avi Format video to yu ...

  9. IISExpress Site information

    Catalog :C:\Users\huxl16\Documents\IISExpress\config applicationhost:applicationhost.config

  10. adopt UIImagePickerController Selected image name information

    - (void)imagePickerController:(UIImagePickerController *)picker didFinishPickingMediaWithInfo:(NSDic ...