Download the Baidu new song and popular songs in python

Source: Internet
Author: User

First of all, it is declared that this tool is only used for learning and does not involve copyright issues, because the songs in Baidu music can be downloaded, and Baidu also provides "Baidu music player ", you can use this tool for batch download.

When I was doing this tool, Baidu didn't provide the "Baidu music player", and I wanted to download it in batches, so I made such a download tool. Of course, it is mainly for learning.

The tool is developed using Python2.7.3 + PyQt.

Function:

1. display the list of songs that can be downloaded from Baidu's new songs or popular songs.

2. Supports the download of one or more songs.

3. You can copy all the link content in the Song Form to create a download group in download tools such as thunder.

Defects:

Currently, a single thread is used, which is less efficient and the UI is prone to false positives.

The running process of this tool is as follows:

1. Simulate user logon to Baidu.

2. If the logon is successful, collect and parse the page content and load the list of tickets.

3. Click the Download button or the batch Download button to download the songs.

 

Usage:

1. At the end of the configuration file setting. py, configure the account and password that can be logged on to Baidu, And the URL of Baidu hot song or new song.

Username = "your baidu acount" # configure your baidu account password = "your baidu password" # configure your baidu password musiclistUrl = "http://music.baidu.com/top/dayhot" # http://music.baidu.com/top/new

2. Run the mainWindow. py file directly. If the network speed is poor, it may take 3 or 4 minutes.

After running

1. First, PyQt GUI programming, form layout, and rewriting of controls and controls such as QTableWidget, QProgressBar, and QPushButton were used.

2. Part of network programming is used. urllib, urllib2, and cookielib are used to request webpages and simulate logon to Baidu.

3. Use HTMLParser to parse webpage content and match webpage elements.

4. Use codecs to read and write files.

 

Problems:

1. Encoding Problems, because the file encoding is set to UTF-8 when creating a file, when the content to be written to the file is Chinese and other non-ASCII code content, always prompt Encoding Problems. In fact, Baidu music Web pages are all UTF-8 format, so the content obtained from the web page is also UTF-8 format, but to talk about the content written into the UTF-8 text, you must decode ("utf8") the webpage content to the unicode format before writing the content normally.

The chardet. detect ("content") method of the chardet module can be used to detect content encoding.

In addition, some download pages may encounter problems when HTMLParser parses the webpage content. Based on the prompt information, the content parameters in the feed () method are decode ("utf8 ") the result is normal.

Decode decodes the content according to the parameter content to the unicode type, depending on the encoding of the collected page.

 

Github: click here

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.