This article mainly introduces how to extract Google music search results using Python. It involves Python's Acquisition Techniques for Google music-related information and has some reference value, for more information about how to extract Google music search results using Python, see the following example. Share it with you for your reference. The details are as follows:
A simple Python script is used to extract the song information on the Google music search page, including the song name, author, album name, and current link. Only 10 pages of results can be extracted.
#! /Usr/bin/env python # coding = UTF-8 ''' Created on 2011-8-19 @ author: yaoboyuan ''' from urllib import request, parseimport re, sysdef extractSongRawData (text ): 'capture the raw data of each song 'text = re. sub ('\ n +', '', text) songList = re. findall ('\
< tbody>
', Text) nums = len (songList) print ('search' + str (nums) + 'song') return songListdef translate (text):' Remove useless characters in text, convert unicode code 'text = re. sub ('\
', '', Text) text = re. sub ('\', '', Text) # find the and translate into chinese s = re. findall ('& # ([0-9] +);', text) if len (s) <= 0: return text else: text = ''for I in range (len (s): value = int (s [I], 10) # from str '000000' to 10 base's int 123 text + = chr (value) # from value to char return textdef extractSongName (song ): 'extract song name' td = re. findall ('(? :\) ', Song) name = re. findall ('. +? \(.*?) \ ', Td [0]) authorName = name [0] authorName = translate (authorName) return authorNamedef extrackAlbumName (song): 'extract album name' td = re. findall ('(? :\0: return td [0] else: return songdef extractLink (song): 'extract song download link 'td = re. findall ('''\
<>