喜歡優酷的視頻,但是要下載它的客戶端才能下載在線的視頻,這一點很多朋友和妹紙都覺得很不爽,我為了自己練手自己寫了一個解析視頻地址的小工具。。。。反正也不是什么高科技,公開一下源代碼,讓大家學習一下。。。
1 import re 2 import sys 3 import urllib 4 import urllib2 5 import datetime 6 from win32clipboard import * 7 from win32con import CF_TEXT 8 9 def get_Clipboard(): 10 OpenClipboard() 11 text = GetClipboardData(CF_TEXT) 12 CloseClipboard() 13 return text 14 15 16 17 class CFlvcd(object): 18 def __init__(self): 19 self.url = "" 20 self.pattern = re.compile(r"<a href *= *\"(http://f\.youku\.com/player/getFlvPath/[^\"]+)") 21 self.headers = {"Accept":"*/*", "Accept-Language":"zh-CN", "":"", 22 "User-Agent":"Mozilla/4.0 (compatible; MSIE 8.0; Windows NT 6.1)", 23 #"Accept-Encoding":"gzip, deflate", 24 "Connection":"Keep-Alive"} 25 26 def parse(self, url): 27 self.url = "http://www.flvcd.com/parse.php?kw=" + url + "&format=super" 28 req = urllib2.Request(url=self.url, headers=self.headers) 29 res = urllib2.urlopen(req) 30 data = res.read() 31 re_res = self.pattern.findall(data) 32 if re_res != None: 33 filename = datetime.datetime.now().strftime("%Y%m%d-%H%M%S.lst") 34 fhandle = open(filename, "w") 35 for url in re_res: 36 # 注意是\r\n還是\n 37 fhandle.write(url + "\n") 38 fhandle.close() 39 print("Parse URL Done!") 40 else: 41 print("URL Not Found") 42 43 def main(): 44 flvcd=CFlvcd() 45 print'你要下載的視頻地址是' 46 print get_Clipboard() 47 print'確定獲取請按1' 48 a=raw_input() 49 if (a=='1'): 50 flvcd.parse(get_Clipboard()) 51 52 53 54 55 if __name__ == "__main__": 56 main()