使用python下载网页上的flash,pythonflash,'''Created o
文章由Byrx.net分享于2019-03-23 09:03:41
使用python下载网页上的flash,pythonflash,'''Created o
'''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 <a href="http://v.youku.com/v_show/id_XMzMzMjE0MjE2.html">http://v.youku.com/v_show/id_XMzMzMjE0MjE2.html super" % sys.argv[0]) exit(1)videourl = sys.argv[1]import urllib2import urlliburl = '<a href="http://www.flvcd.com/parse.php?kw=">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) + '"')#该片段来自于http://byrx.net
相关内容
- Python 兔子毒药问题,python兔子毒药,大致是这样的:1
- python对字典进行排序,python字典排序,1、 准备知识:在
- python解析远程web页面,python解析web,import htmll
- 打印杨辉三角形,杨辉三角形,Python语言: py
- python计算两个日期相差的天数,python天数,#两个日期相
- 在python中使用tempconv模块转换问题,pythontempconv,from te
- # MYSQL 添加 删除 修改 查询 自己写的一个函数,,#!/us
- Python 操作excel,python操作excel,首先安装python2.
- 文本编辑器。学习五天Python,新手第一次发.,,#!/usr/bi
- phpdisk 盲注脚本,phpdisk注脚本,#===========
评论关闭