利用python寫個(gè)下載teahour音頻的小腳本
前言
最近空閑的時(shí)候看到了之前就關(guān)注的一個(gè)小站http://teahour.fm/,一直想把這里的音頻都聽一遍,可轉(zhuǎn)眼間怎么著也有兩年了,卻什么也沒做。有些傷感,于是就寫了個(gè)腳本,抓了下音頻的下載鏈接,等下載下來后一定要認(rèn)真聽聽。
時(shí)間倉促,加調(diào)試也就那么十幾分鐘,腳本寫的可能有些爛,大家可以留言指出。
teahour.py
#!/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的部分內(nèi)容如下:
peiqiang@budongdeMacBook-Pro:~/Downloads/teahour$ cat teahour.sh wget 'http://screencasts.b0.upaiyun.com/podcasts/teahour_episode_89.m4a' -SO '89 和玎玎聊聊如何搭建精益創(chuàng)業(yè)團(tuán)隊(duì).m4a' wget 'http://screencasts.b0.upaiyun.com/podcasts/teahour_episode_88.m4a' -SO '88 與墨刀創(chuàng)始人張?jiān)涣膭?chuàng)業(yè)從 0 到 1.m4a' wget 'http://screencasts.b0.upaiyun.com/podcasts/teahour_episode_87.m4a' -SO '87 和互聯(lián)網(wǎng)老兵高春輝聊 IPIP.net.m4a' wget 'http://screencasts.b0.upaiyun.com/podcasts/teahour_episode_86.mp3' -SO '86 和『掘金』創(chuàng)始人陰明聊聊創(chuàng)業(yè)和技術(shù).mp3' wget 'http://screencasts.b0.upaiyun.com/podcasts/teahour_episode_85.mp3' -SO '85 這次我們聊聊遠(yuǎn)程工作.mp3'
執(zhí)行腳本sh teahour.sh下載的部分內(nèi)容如下:
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 繼續(xù)跟 Robbin 聊聊技術(shù)人的戰(zhàn)略與戰(zhàn)術(shù).m4a -rw-r--r-- 1 peiqiang staff 89519924 6 12 2016 85 這次我們聊聊遠(yuǎn)程工作.mp3 -rw-r--r-- 1 peiqiang staff 87766246 8 8 2016 86 和『掘金』創(chuàng)始人陰明聊聊創(chuàng)業(yè)和技術(shù).mp3 -rw-r--r-- 1 peiqiang staff 59058564 9 11 2016 87 和互聯(lián)網(wǎng)老兵高春輝聊 IPIP.net.m4a -rw-r--r-- 1 peiqiang staff 32408522 10 26 15:55 88 與墨刀創(chuàng)始人張?jiān)涣膭?chuàng)業(yè)從 0 到 1.m4a -rw-r--r-- 1 peiqiang staff 43051575 11 8 18:49 89 和玎玎聊聊如何搭建精益創(chuàng)業(yè)團(tuán)隊(duì).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
總結(jié)
以上就是這篇文章的全部內(nèi)容了,希望本文的內(nèi)容對(duì)大家的學(xué)習(xí)或者工作能帶來一定的幫助,如果有疑問大家可以留言交流,謝謝大家對(duì)腳本之家的支持。
相關(guān)文章
python實(shí)現(xiàn)忽略大小寫對(duì)字符串列表排序的方法
這篇文章主要介紹了python實(shí)現(xiàn)忽略大小寫對(duì)字符串列表排序的方法,通過三種不同的方法實(shí)現(xiàn)了對(duì)字符串的排序,是非常實(shí)用的技巧,需要的朋友可以參考下2014-09-09
pytorch torch.gather函數(shù)的使用
torch.gather 是 PyTorch 中用于在指定維度上通過索引從源張量中提取元素的函數(shù),它需要輸入張量、維度索引和索引張量,示例代碼展示了如何使用 torch.gather 從輸入張量中按索引提取元素,返回的結(jié)果張量形狀與索引張量相同2024-09-09
python實(shí)現(xiàn)自動(dòng)化辦公郵件合并功能
這篇文章主要介紹了python實(shí)現(xiàn)自動(dòng)化辦公郵件合并功能,本文通過實(shí)例代碼給大家介紹的非常詳細(xì),對(duì)大家的學(xué)習(xí)或工作具有一定的參考借鑒價(jià)值,需要的朋友可以參考下2021-07-07
Python腳本,標(biāo)識(shí)符,變量使用,腳本語句,注釋,模塊引用詳解
這篇文章主要為大家詳細(xì)介紹了Python腳本,標(biāo)識(shí)符,變量使用,腳本語句,注釋,模塊引用,文中示例代碼介紹的非常詳細(xì),具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下2022-02-02
python制作一個(gè)簡單的gui 數(shù)據(jù)庫查詢界面
這篇文章主要介紹了python制作一個(gè)簡單的gui 數(shù)據(jù)庫查詢界面,幫助大家更好的理解和學(xué)習(xí)python tkinter的使用,感興趣的朋友可以了解下2020-11-11
Python pyinstaller實(shí)現(xiàn)圖形化打包工具
這篇文章主要介紹了一個(gè)使用Python PYQT5制作的關(guān)于pyinstaller打包工具,代替?zhèn)鹘y(tǒng)的cmd黑窗口模式打包頁面,實(shí)現(xiàn)更快捷方便的python打包體驗(yàn),希望對(duì)大家有所幫助2025-01-01

