Obtain the daily voice (python) and python
Get luogic's daily voice (python) by Wu xueying
I always like to listen to luogic's thinking, but it's troublesome to order the public account every day, and it's hard to listen for a minute every day. So today I suddenly want to merge them all, it is not better to hear all the time. so, start: the Internet to find the next, found that there is already a website mp3, so to climb its data (you can also directly go to the luogic thinking official website of the Data http://www.ljsw.cc)
Import re, urllib2
F = file('luoji.txt ', 'w ')
Def getHtmlCode (url ):
Return urllib2.urlopen (url). read ()
Def getTitle (htmlString ):
RegTitle = re. compile ("xst \"> (. + ?) ")
ReturnregTitle. findall (htmlString)
Def getMp3Url (htmlString ):
RegMp3 = re. compile ("http (. ++ ?). Mp3 \'")
ReturnregMp3.findall (htmlString)
Def getLuojiContent (url ):
HtmlCode = getHtmlCode (url)
Titles = getTitle (htmlCode)
Urls = getUrl (htmlCode)
For I in range (0, len (urls )):
Printtitles [I]
F. write (titles [I] + '-')
ContentHtml = getHtmlCode (urls [I])
Contents = getMp3Url (contentHtml)
Iflen (contents)> 0:
Mp3Url = 'http' + contents [0] Comment 'region'
Print mp3Url
F. write (mp3Url + '\ n ')
If _ name _ = '_ main __':
For I in range (1, 38 ):
Printstr (I)
Url = 'HTTP: // www. ljsw. cc/forum-39-'+ str (I) + '.html'
Try:
GetLuojiContent (url)
Print 'finished: '+ str (I)
Except t:
Printstr (I) + ': error! '
Download mp3 files: # coding = UTF-8
Import re, urllib2, OS
For line in open ("luoji.txt "):
Contents = line. split ('-')
Url = line [11: len (line)-1]
Cmd = 'curl-O "% s" '% (url)
OS. system (cmd)
FileName = url. split ('/')
Name = fileName [len (fileName)-1]
OS. rename (name, contents [0] employee 'others ')
Merge mp3 files: from glob import iglob
Import shutil
Import OS
PATH = r'mp3'
Destination = open('luojie', 'wb ')
For filename in iglob (OS. path. join (PATH, '*. mp3 ')):
Shutil. copyfileobj (open (filename, 'rb'), destination) destination. close ()
So you can listen one by one or listen together.
All python code: github code
All mp3 files: Link: http://pan.baidu.com/s/1nt5L7Pf password: 5mrg