gpt4 book ai didi

利用python写个下载teahour音频的小脚本

转载 作者:qq735679552 更新时间:2022-09-27 22:32:09 25 4
gpt4 key购买 nike

CFSDN坚持开源创造价值,我们致力于搭建一个资源共享平台,让每一个IT人在这里找到属于你的精彩世界.

这篇CFSDN的博客文章利用python写个下载teahour音频的小脚本由作者收集整理,如果你对这篇文章有兴趣,记得点赞哟.

前言 。

最近空闲的时候看到了之前就关注的一个小站http://teahour.fm/,一直想把这里的音频都听一遍,可转眼间怎么着也有两年了,却什么也没做。有些伤感,于是就写了个脚本,抓了下音频的下载链接,等下载下来后一定要认真听听.

时间仓促,加调试也就那么十几分钟,脚本写的可能有些烂,大家可以留言指出.

teahour.py 。

?
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
#!/usr/bin/env python
#coding: utf-8
 
import sys
import requests
from BeautifulSoup import BeautifulSoup
 
reload (sys)
sys.setdefaultencoding( "utf-8" )
 
def parse_index():
  l = []
  r = requests.get( "http://teahour.fm/" )
  text = r.text
  html = BeautifulSoup(text)
  a = html.findAll( "ul" )[ - 3 ].findAll( "a" )
  for item in a:
   url = " ".join([" http: / / teahour.fm",item.attrs[ 0 ][ 1 ]])
   title = item.text
   title = title.strip( "#" )
   l.append((title,url))
  return l
 
def write(lines):
  with open ( "teahour.sh" , "a" ) as fh:
   fh.writelines(lines)
 
def parse_sub(t):
  title,url = t
  r = requests.get(url)
  text = r.text
  html = BeautifulSoup(text)
  audio_url = html.find( "audio" ).attrs[ - 1 ][ - 1 ]
  ext = audio_url.split( "." )[ - 1 ]
  line = "wget '%s' -SO '%s.%s'\n" % (audio_url,title,ext)
  #print line
  return line
 
def main():
  lines = []
  l = parse_index()
  for t in l:
   line = parse_sub(t)
   lines.append(line)
  write(lines)
 
if __name__ = = "__main__" :
  main()

文本teahour.sh的部分内容如下

?
1
2
3
4
5
6
peiqiang@budongdeMacBook-Pro:~/Downloads/teahour$ cat teahour.sh
wget 'http://screencasts.b0.upaiyun.com/podcasts/teahour_episode_89.m4a' -SO '89 和玎玎聊聊如何搭建精益创业团队.m4a'
wget 'http://screencasts.b0.upaiyun.com/podcasts/teahour_episode_88.m4a' -SO '88 与墨刀创始人张元一聊创业从 0 到 1.m4a'
wget 'http://screencasts.b0.upaiyun.com/podcasts/teahour_episode_87.m4a' -SO '87 和互联网老兵高春辉聊 IPIP.net.m4a'
wget 'http://screencasts.b0.upaiyun.com/podcasts/teahour_episode_86.mp3' -SO '86 和『掘金』创始人阴明聊聊创业和技术.mp3'
wget 'http://screencasts.b0.upaiyun.com/podcasts/teahour_episode_85.mp3' -SO '85 这次我们聊聊远程工作.mp3'

执行脚本sh teahour.sh下载的部分内容如下

?
1
2
3
4
5
6
7
8
9
10
11
peiqiang@budongdeMacBook-Pro:~/Downloads/teahour$ ll
total 1077896
-rw-r--r-- 1 peiqiang staff 130416640 3 16 20:02 83 这次我们聊聊超酷的Ethereum.m4a
-rw-r--r-- 1 peiqiang staff 109631418 3 3 2016 84 继续跟 Robbin 聊聊技术人的战略与战术.m4a
-rw-r--r-- 1 peiqiang staff 89519924 6 12 2016 85 这次我们聊聊远程工作.mp3
-rw-r--r-- 1 peiqiang staff 87766246 8 8 2016 86 和『掘金』创始人阴明聊聊创业和技术.mp3
-rw-r--r-- 1 peiqiang staff 59058564 9 11 2016 87 和互联网老兵高春辉聊 IPIP.net.m4a
-rw-r--r-- 1 peiqiang staff 32408522 10 26 15:55 88 与墨刀创始人张元一聊创业从 0 到 1.m4a
-rw-r--r-- 1 peiqiang staff 43051575 11 8 18:49 89 和玎玎聊聊如何搭建精益创业团队.m4a
-rwxr-xr-x@ 1 peiqiang staff  1055 3 16 20:02 teahour.py
-rw-r--r-- 1 peiqiang staff  11465 3 16 19:57 teahour.sh

总结 。

以上就是这篇文章的全部内容了,希望本文的内容对大家的学习或者工作能带来一定的帮助,如果有疑问大家可以留言交流,谢谢大家对我的支持.

原文链接:http://peiqiang.net/2017/03/16/download-teahour-fm-audio-1.html 。

最后此篇关于利用python写个下载teahour音频的小脚本的文章就讲到这里了,如果你想了解更多关于利用python写个下载teahour音频的小脚本的内容请搜索CFSDN的文章或继续浏览相关文章,希望大家以后支持我的博客! 。

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com