1.download title and url

#!/usr/bin/env python

#-*- coding:utf-8 -*-

import re, urllib2,threading

def geturltitle(match, file):
    s = match.group();
    p = re.compile(r'^\[mukio=file\]');
    downurl = re.sub(p, '', s);     print downurl;
    # 过滤url
    if downurl:
        file.writelines(downurl);
        file.write('\n');
        # for line in downurl:
        #     file.write(line);     # 过滤title
    pattern1 = re.compile(r'<meta name="keywords" content="\S.*"');
    match1 = pattern1.search(respread);
    if match1:
        s1 = match1.group();
        p1 = re.compile(r'^<meta name="keywords" content="');
        title = re.sub(p1, '', s1);
        print title;
        if title:
            file.writelines(title);
            file.write('\n\n');
            # for line in title:
            #     file.write(line); while 1:
    file = open('avfun1.txt', 'w');
    for  n in range(3600,9000):
        try:
            resp = urllib2.urlopen('http://www.avfun1.com/forum.php?mod=viewthread&tid='+repr(n)+'&mobile=yes', timeout = 2);
            respread = resp.read();
            pattern = re.compile(r'\[mukio=file\]\S.*mp4');
            match = pattern.search(respread);
            print "pid = " + repr(n)             if match:
                threading.Thread(target=geturltitle(match, file)).start();
            # else:
            #     continue;
            pass
        except Exception, e:
            print e;
            pass
        else:
            pass
        finally:
            pass
        
    file.close();
    break;

2.rename title from file

#!/usr/bin/env python
#-*- coding:utf-8 -*- import re, os dir = "/Users/apple/Downloads/avfun1/" #文件目录 if os.path.isdir(dir): #检验目录是否有误
  print ("Directory exists!")
else:
  print ("Directory not exist.") filelist=os.listdir(dir+'aaa') file = open(dir+'avfun1.txt', 'rb'); dir = dir + 'aaa' '''for line in file:
    print line
'''
str = file.read() for name in filelist:
    match = re.search(name+r'\n\S.*', str)     if match:
        str1 = match.group();
        tt_match = re.search(r'[^\d.mp4\n].*$', str1)         newfile = tt_match.group()+'.mp4' #获取匹配名存为newfile
        print name
        print newfile
        os.rename(os.path.join(dir,name),os.path.join(dir,newfile))
        
    else:

print match

最新文章

  1. R笔记 单样本t检验 功效分析
  2. dotNet使用HttpWebRequest模拟浏览器
  3. 最小/大费用最大流模板(codevs1914)
  4. PYTHON 迭代器
  5. 【linux】英文显示乱码解决
  6. poj 1141 区间dp+递归打印路径
  7. [golang]反射的用处--代码自动生成
  8. jQuery基础 - 改变CSS样式
  9. QT 字符串相等间距字符间增加字符
  10. 01.C语言关于结构体的学习笔记
  11. hive-初看hive
  12. java jvm学习笔记五(实践自己写的类装载器)
  13. jaspersoft 5.6.0 相关问题
  14. .NET Core TDD 前传: 编写易于测试的代码 -- 单一职责
  15. DirectX11--HR宏关于dxerr库的替代方案
  16. 使用smb映射到本地时 访问权限,请联系管理员错误
  17. APP压力稳定性测试之monkey环境搭建
  18. kettle的下载、安装和初步使用(windows平台下)(图文详解)
  19. 前端性能优化 —— 减少HTTP请求
  20. 记录ssh暴力破解的密码字典

热门文章

  1. Eigen中的noalias(): 解决矩阵运算的混淆问题
  2. Node中的console控制台
  3. js微信摇一摇功能以及api
  4. vue-cli 【flexible】屏幕字体自适应布局及配置
  5. 基于SpringBoot+MyBatis实现一套电商系统
  6. 学习Spring Boot看这两个开源项目就够了!非得值得收藏的资源
  7. hibernate添加帮助文档和源码
  8. ios wkwebview 跳转到新的controllerview加载页面 出现闪退问题
  9. jq解析xml
  10. VMware虚拟机文件(后缀)详解