0

在空闲时间,我用 Python 语言编写了这个脚本。

import urllib2

class SearchMP3:

    def download(self):

        url = self.url_base + self.title + self.mid_url + self.artist

        mp3file = urllib2.urlopen(self.url_base + self.title + self.mid_url + self.artist + self.end_url)
        output = open(self.title + '.mp3','wb')
        mp3file.addheaders = [('User-agent', 'Mozilla/5.0')]
        mp3file.addheaders = [('Host', 's14.searchmp3.mobi')]
        mp3file.addheaders = [('Referer', url)]
        output.write(mp3file.read())
        output.close()

    def url(self):
        self.url_base = 'http://searchmp3.mobi/'
        self.mid_url = '-mp3'
        self.end_url = '?download=1'
        SearchMP3.download()

    def data(self):
        print 'Welcome to SearchMP3Mobi download service.'
        self.artist = raw_input()
        self.artist.replace('','-')
        self.title = raw_input()
        self.title.replace('','-')
        SearchMP3.url()

if __name__ == '__main__':
    SearchMP3 = SearchMP3()
    SearchMP3.data()

脚本没有报错,但是下载后的文件大小以KB为单位。为什么?这里我使用urlopen,我可以使用请求模式从这个站点下载mp3吗?

谢谢!

4

0 回答 0