• linkedu视频
  • 平面设计
  • 电脑入门
  • 操作系统
  • 办公应用
  • 电脑硬件
  • 动画设计
  • 3D设计
  • 网页设计
  • CAD设计
  • 影音处理
  • 数据库
  • 程序设计
  • 认证考试
  • 信息管理
  • 信息安全
菜单
linkedu.com
  • 网页制作
  • 数据库
  • 程序设计
  • 操作系统
  • CMS教程
  • 游戏攻略
  • 脚本语言
  • 平面设计
  • 软件教程
  • 网络安全
  • 电脑知识
  • 服务器
  • 视频教程
  • vbs
  • DOS/BAT
  • hta/htc
  • python
  • perl
  • VBA
  • ColdFusion
  • ruby
  • PowerShell
  • Lua
  • Golang
  • linux shell
您的位置:首页 > 脚本语言 >python > Python获取apk文件URL地址实例

Python获取apk文件URL地址实例

作者: 字体:[增加 减小] 来源:互联网

通过本文主要向大家介绍了python url,python url编码,python url解码,python正则匹配url,python 取url的域名等相关知识,希望对您有所帮助,也希望大家支持linkedu.com www.linkedu.com

工作中经常需要提取apk文件的特定URL地址,如是想到用Python脚本进行自动处理。
需要用到的Python基础知识如下:
os.walk()
函数声明:os.walk(top,topdown=True,onerror=None)
(1)参数top表示需要遍历的顶级目录的路径。
(2)参数topdown的默认值是“True”表示首先返回顶级目录下的文件,然后再遍历子目录中的文件。当topdown的值为"False"时,表示先遍历子目录中的文件,然后再返回顶级目录下的文件。
(3)参数onerror默认值为"None",表示忽略文件遍历时的错误。如果不为空,则提供一个自定义函数提示错误信息后继续遍历或抛出异常中止遍历。
返回值:函数返回一个元组,含有三个元素。这三个元素分别是:每次遍历的路径名、路径下子目录列表、目录下文件列表。
os.walk使用实例:删除某个文件夹(当然可以通过os.listdir的递归调用删除)

def Remove_dir(top_dir):
    if os.path.exists(top_dir)==False:
        print "not exists"
        return
    if os.path.isdir(top_dir)==False:
        print "not a dir"
        return
    for dir_path,subpaths,files in os.walk(top_dir,False):
        for file in files:
            file_path=os.path.join(dir_path,file)
            print "delete file:%s"  %file_path
            os.remove(file_path)
        print "delete dir:%s" %dir_path
        os.rmdir(dir_path)

#调用
Remove_dir(r"C:\Users\Administrator\Desktop\abc")
</div>
Python执行系统命令的方法 os.system(),os.popen(),commands.getstatusoutput() 
os.system()无法获得到输出和返回值;
通过os.popen() 返回的是 file read 的对象,对其进行读取 read() 的操作可以看到执行的输出,但是得不到返回值。
通过 commands.getstatusoutput() 方法就可以获得到返回值和输出  
(status, output) = commands.getstatusoutput('cat /proc/cpuinfo') 
3.  Python中operator模块的contains(...) 函数
contains(a, b) -- Same as b in a (note reversed operands). 判断b是否被a包含 
基础知识介绍完了,可以上代码了:

inputdir = "./tmp"

for path, dir, files in os.walk(inputdir):
    for file in files:
    if not file.endswith('.apk'):
        #print "not apk file."
        continue
    apkpath = os.path.join(inputdir, file)
    cmd = './xxx -d %s' %apkpath
    output = os.popen(cmd)
    s = set()
    #按行查找URL
    for line in output:
        if operator.contains(line, "http://"):
            #print tmp
            start = line.index('''http://''')
            end = line.index('''"''',start)
            url = line[start:end]
            s.add(url)
    cmd = './yyy -t a.expense.mdk.a.tvd %s' %apkpath
    #获取命令执行结果及返回值
    status, output = commands.getstatusoutput(cmd)
#    print output

    if output.startswith('find'):
        print output

        for url in s:
            if url.find('imei')!=-1:
                print 'url is %s' %url.strip()
        #print '========================='
    s = ''
</div>

</div>

您可能想查找下面的文章:

  • Python urls.py的三种配置写法实例详解
  • Python 中urls.py:URL dispatcher(路由配置文件)详解
  • Python爬取qq music中的音乐url及批量下载
  • Python 中urls.py:URL dispatcher(路由配置文件)详解
  • Python爬取qq music中的音乐url及批量下载
  • python 获取网页编码方式实现代码
  • python检查URL是否正常访问的小技巧
  • 【Python】Python的urllib模块、urllib2模块批量进行网页下载文件
  • Python网络编程中urllib2模块的用法总结
  • python实现中文转换url编码的方法

相关文章

  • 在Python的web框架中编写创建日志的程序的教程
  • Python os模块中的isfile()和isdir()函数均返回false问题解决方法
  • python实现的AES双向对称加密解密与用法分析
  • Python的Flask框架中使用Flask-SQLAlchemy管理数据库的教程
  • Python中list初始化方法示例
  • Python基于smtplib实现异步发送邮件服务
  • python入门之语句(if语句、while语句、for语句)
  • python实现比较两段文本不同之处的方法
  • Python之日期与时间处理模块(date和datetime)
  • Python中死锁的形成示例及死锁情况的防止

文章分类

  • vbs
  • DOS/BAT
  • hta/htc
  • python
  • perl
  • VBA
  • ColdFusion
  • ruby
  • PowerShell
  • Lua
  • Golang
  • linux shell

最近更新的内容

    • Django框架中方法的访问和查找
    • Python常用正则表达式符号浅析
    • python实现DES加密解密方法实例详解
    • python笔记(1) 关于我们应不应该继续学习python
    • Python和JavaScript间代码转换的4个工具
    • Python bsddb模块操作Berkeley DB数据库介绍
    • Python实现微信公众平台自定义菜单实例
    • Python的SQLalchemy模块连接与操作MySQL的基础示例
    • Python实现遍历目录的方法【测试可用】
    • Python中的文件和目录操作实现代码

关于我们 - 联系我们 - 免责声明 - 网站地图

©2020-2025 All Rights Reserved. linkedu.com 版权所有