日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 > 编程语言 > python >内容正文

python

python示例apk_Python获取apk文件URL地址实例

發布時間:2025/3/15 python 34 豆豆
生活随笔 收集整理的這篇文章主要介紹了 python示例apk_Python获取apk文件URL地址实例 小編覺得挺不錯的,現在分享給大家,幫大家做個參考.

工作中經常需要提取apk文件的特定URL地址,如是想到用Python腳本進行自動處理。

需要用到的Python基礎知識如下:

os.walk()

函數聲明:os.walk(top,topdown=True,οnerrοr=None)

(1)參數top表示需要遍歷的頂級目錄的路徑。

(2)參數topdown的默認值是“True”表示首先返回頂級目錄下的文件,然后再遍歷子目錄中的文件。當topdown的值為"False"時,表示先遍歷子目錄中的文件,然后再返回頂級目錄下的文件。

(3)參數onerror默認值為"None",表示忽略文件遍歷時的錯誤。如果不為空,則提供一個自定義函數提示錯誤信息后繼續遍歷或拋出異常中止遍歷。

返回值:函數返回一個元組,含有三個元素。這三個元素分別是:每次遍歷的路徑名、路徑下子目錄列表、目錄下文件列表。

os.walk使用實例:刪除某個文件夾(當然可以通過os.listdir的遞歸調用刪除)

復制代碼 代碼如下:

#! /usr/bin/env python

#coding=utf-8

import os

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")

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包含

基礎知識介紹完了,可以上代碼了:

復制代碼 代碼如下:

import os

import operator

import commands

#from signature import *

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 = ''

本文標題: Python獲取apk文件URL地址實例

本文地址: http://www.cppcns.com/jiaoben/python/100954.html

總結

以上是生活随笔為你收集整理的python示例apk_Python获取apk文件URL地址实例的全部內容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網站內容還不錯,歡迎將生活随笔推薦給好友。