Get the daily WeChat voice (python) and luogic python

Source: Internet
Author: User

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

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.