使用python下载网页上的flash,pythonflash,[Python]代码''
使用python下载网页上的flash,pythonflash,[Python]代码''
[Python]代码
'''Created on 2012-7-18@author: Administrator'''import sysdef output(s): sys.stderr.write(s + "\n")argc = len(sys.argv)if argc == 2: format = 'super'elif argc == 3: format = sys.argv[2]else: output("Usage: %s videourl [videoquality=normal|high|super|...]" % sys.argv[0]) output(" e.g."); output(" %s http://v.youku.com/v_show/id_XMzMzMjE0MjE2.html super" % sys.argv[0]) exit(1)videourl = sys.argv[1]import urllib2import urlliburl = 'http://www.flvcd.com/parse.php?kw=' + urllib.quote(videourl) + '&format=' + formatreq = urllib2.Request(url)req.add_header("host", "www.flvcd.com")req.add_header("Referer", url[:-4])req.add_header('User-Agent', 'Mozilla/5.0 (Macintosh; Intel Mac OS X 10.6; rv:2.0) Gecko/20100101 Firefox/4.0')req.add_header('Accept-Language', 'en-us,en;q=0.5')req.add_header('Accept-Encoding', 'gzip, deflate')req.add_header('Accept-Charset', 'ISO-8859-1,utf-8;q=0.7,*;q=0.7')req.add_header('Keep-Alive', '115')res = urllib2.urlopen(req)html = res.read()import repattern = re.compile('<input\s+type="hidden"\s+name="inf"\s+value="([^"]+)')firstmatch = pattern.search(html)urls = firstmatch.group(1)urls = unicode(urls, 'gbk')urlpattern = re.compile('<[NU]>(.+)');result = urlpattern.findall(urls)data = [result[i:i+2] for i in range(0, len(result), 2)]count = len(data)files = []output('\n--- Start to download from url "%s" (%d block(s) in total):' % (videourl, count))for k, v in enumerate(data): output(' >downloading Block %.2d of %.2d ...' % (k+1, count)) urllib.urlretrieve(v[1], v[0] + '.flv') files.append( (v[0] + '.flv').replace('"', '\\"').replace('$', '\$').encode('utf-8') ) output(' downloaded Block.%.2d completely<' % (k+1,))output('--- finished ---\n')print('"' + '" "'.join(files) + '"')
相关内容
- Python 批量获取《oschina》高亮代码区域源码!,python《
- Find bridges of graph,bridgesgraph,[Python]代码#
- 用Python实现一个简单的算术游戏,python实现算术,#!/us
- 绑定修改网卡绑定关系脚本,修改网卡绑定脚本,[Pyth
- 判断图片分辨率并修改,判断图片分辨率,[Python]代码
- 调节图片亮度和饱和度,图片亮度饱和度,[Python]代码
- 九九乘法表,乘法,[Python]代码im
- 从WeatherCN上提取天气数据,weathercn提取天气,# -*- codin
- Python信息录入小系统(使用shelve),pythonshelve,Python s
- python监控日志并予以清理,python监控日志,Daemonize.py
评论关闭