分享

python脚本抓取优酷在线视频地址代码

 free_light 2014-04-30
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./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()

    本站是提供个人知识管理的网络存储空间,所有内容均由用户发布,不代表本站观点。请注意甄别内容中的联系方式、诱导购买等信息,谨防诈骗。如发现有害或侵权内容,请点击一键举报。
    转藏 分享 献花(0

    0条评论

    发表

    请遵守用户 评论公约

    类似文章 更多