Python Pick the music network, the GUI implementation of music player, Invincible Pythoner refining into mind!

Source: Internet
Author: User
Tags xpath

Today, a few blog posts are some of the python pure dry, difficult, but also less difficult to fit the novice. But none of them, is that they will have the source + video tutorial Two in one for everyone to learn. This article has a benefit, my article many times by others copy to other sites, so it wants to copy at least more to move the brain

The tutorial in this blog is a python crawl of a music network resource, GUI to create a music player, two tutorials are released together.

First, how to use Python to crawl a nice light music network

Do not understand, directly look at the code, code can not understand? Find videos at the end of this article!

Import Python third-party request library

Import requests

Import third-party parsing libraries

From lxml import etree

The Urllib library has a dedicated method for downloading

From urllib.request import Urlretrieve

Video capture

1, understand the structure of the Web page!

    • Requestor-> Parser-Download (Learn about)
    • Requestor, URL Manager, Scheduler-> Parser, Downloader (face object, Enterprise development)

2. Define the request function

    • Send a request and get a response
    • Returns the result of our response text type

3. Analytic home page function

    • Converts a text file to an object that can be parsed by the XPath syntax, extracting all the incomplete URLs
    • Define an empty list to store our spliced URLs
    • Walk through our list, add the URL to our new empty list using the Append method
    • Returns a list of URLs that have been added.

4. Define a function that resolves a list

    • Convert text files to objects that can be parsed by XPath syntax, extract the song name and number of each song
    • Define an empty list to store the complete list of MP3
    • Iterate through numbered lists, take out numbers, and combine the full URLs
    • Put a well-stitched URL into the list and return to the full URL dictionary

5. Download function

    • Download method, receive two parameters, one is address, one is save path
    • Define a main function, program entry (main function), code logic
    • Call our request function to get the return result of a home page
    • Call parse function, parse homepage, get URL of all list page
    • Traverse the URLs of all list pages
    • Call the request function, pass in the URL, get the text file of the list page
    • Invokes a function that resolves a list page, returning all MP3 URLs
    • Call the Download function

Python Source:

Python_gui Create music player source code sharing

Simple version:

Code:

Python Pick the music network, the GUI implementation of music player, Invincible Pythoner refining into mind!

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.