Python实现对Android截图
背景:
测试过程中,总是需要对Android设备进行截图,然后在截图中标注问题描述;
手动方式:
1.使用adb scrrencap /sdcard/screen.png 命令对Android设备进行截图
2.然后再使用adb pull /sdcard/scrren.png导入到PC端
3.使用QQ截图进行问题描述标注
自动化实现:
将scrrencap.py文件copy至某个目录下,直接执行将保存截图到当前目录并自动打开展示;
C:\>screencap.py
使用方法:
C:\>screencap.py -h
Usage: screencap.py [-d <directory> -f <filename>] Automatic screenshots for android, After in PC display . Options:
-h, --help show this help message and exit
-d DIRECTORY, --dir=DIRECTORY
directory of save the address
-f FILENAME, --filename=FILENAME
filename of screen shots file name
import os
import time
from optparse import OptionParser def option():
# 获取脚本所在当前目录
current_dir = os.path.dirname(__file__)
# 根据截图时间生成默认文件名:20170722142831.png
file_name = "%s.png" % time.strftime("%Y%m%d%H%M%S", time.localtime()) usage = "screencap.py [-d <directory> -f <filename>]"
description = "Automatic screenshots for android, After in PC display ." p = OptionParser(usage=usage, description=description) p.add_option("-d", "--dir",
dest="directory", default=current_dir,
help="directory of save the address") p.add_option("-f", "--filename",
dest="filename", default=file_name,
help="filename of screen shots file name")
return p.parse_args() def screen(options):
# 截图
print(os.popen("adb shell screencap /sdcard/{filename}".format(filename=options.filename)).read()) # 截图导出
print(os.popen(r"adb pull /sdcard/{filename} {dir}".format(filename=options.filename,
dir=options.directory)).read())
# 打开截图
print(os.popen(r"start {filename}".format(filename=options.filename)).read())
# 删除截图
print(os.popen("adb shell rm /sdcard/{filename}".format(filename=options.filename))) if __name__ == '__main__':
options, args = option()
# print(options)
# print(args)
screen(options)
screencap.py
Python实现对Android截图的更多相关文章
- 基于Python实现对PDF文件的OCR识别
http://www.jb51.net/article/89955.htm https://pythontips.com/2016/02/25/ocr-on-pdf-files-using-pytho ...
- 利用Python实现对Web服务器的目录探测
今天是一篇提升技能的干货分享,操作性较强,适用于中级水平的小伙伴,文章阅读用时约3分钟. PART 1/Python Python是一种解释型.面向对象.动态数据类型的高级程序设计语言. Python ...
- 利用 python 实现对web服务器的目录探测
一.pythonPython是一种解释型.面向对象.动态数据类型的高级程序设计语言.python 是一门简单易学的语言,并且功能强大也很灵活,在渗透测试中的应用广泛,让我们一起打造属于自己的渗透测试工 ...
- 通过Python实现对SQL Server 数据文件大小的监控告警
1.需求背景 系统程序突然报错,报错信息如下: The transaction log for database '@dbname' is full. To find out why space in ...
- Python实现对CSV文件的读写功能
我们要处理csv文件,首先要的导入csv模块 import csv #读取csv文件def readCsv(path): #传入变量csv文件的路径 list=[] #定义一个空列表 with ope ...
- python实现对excel数据进行修改/添加
import osimport xlrdfrom xlutils.copy import copydef base_dir(filename=None): return os.path.join(os ...
- Python实现对excel的操作
1.操作excel使用第三方库openpyxl安装:pip install openpyxy引入:import openpyxl2.常用简单操作1)打开excel文件获取工作簿wb = openpyx ...
- 用 Python 脚本实现对 Linux 服务器的监控
目前 Linux 下有一些使用 Python 语言编写的 Linux 系统监控工具 比如 inotify-sync(文件系统安全监控软件).glances(资源监控工具)在实际工作中,Linux 系统 ...
- 用 Python 脚本实现对 Linux 服务器的网卡流量监控
*这篇文章网上已经有相关代码,为了加深印象,我做了相关批注,希望对朋友们有帮助 工作原理:基于/proc文件系统 Linux 系统为管理员提供了非常好的方法,使其可以在系统运行时更改内核,而不需要重新 ...
随机推荐
- 对Tomcat启动或运行时,项目对jar包依赖路径的一些粗浅认知
Tomcat在运行webapp项目的时候,需要各种依赖jar包.它会从2个地方去找这些包 1.Tomcat自己的lib目录中 2.webapp目录下,webapps\{项目}\WEB-INF\lib ...
- C# 集合-并发处理-锁OR线程 (转载)
每次写博客,第一句话都是这样的:程序员很苦逼,除了会写程序,还得会写博客!当然,希望将来的一天,某位老板看到此博客,给你的程序员职工加点薪资吧!因为程序员的世界除了苦逼就是沉默.我眼中的程序员大多都不 ...
- C语言位域解析&符号位扩展规则
从一个例子说起: int main(void){ union{ int i; struct{ ; ; ; }bits; }num; printf("Input an integer for ...
- Python mysql-表中数据的大量插入
2017-09-06 23:28:26 import pymysql db = pymysql.connect("localhost","root"," ...
- 雷林鹏分享:C# 属性(Property)
C# 属性(Property) 属性(Property) 是类(class).结构(structure)和接口(interface)的命名(named)成员.类或结构中的成员变量或方法称为 域(Fie ...
- 雷林鹏分享:Ruby 判断
Ruby 判断 Ruby 提供了其他现代语言中很常见的条件结构.在这里,我们将解释所有的条件语句和 Ruby 中可用的修饰符. Ruby if...else 语句 语法 if conditional ...
- English trip -- MC(情景课)3 D
xu言: have a nice weekend... sentences How many people are there in you family? they are 3 people in ...
- English trip -- VC(情景课)2 C Where's my pencli?
Grammar focus 语法点: in 和 on in the desk 在桌子抽屉里 on the desk 在桌子面上 Practice 练习 Where's my pencil? I ...
- IntelliJ IDEA 进行多线程调试
idea的断点有不同的模式,只有当Thread模式下才能调试多线程 断点设置步骤: 1.在断点上右键 2.选择Thread,然后点Done(建议选择Thread后点击make default把 ...
- LeetCode--168--Excel表列名称
问题描述: 给定一个正整数,返回它在 Excel 表中相对应的列名称. 例如, 1 -> A 2 -> B 3 -> C ... 26 -> Z 27 -> AA 28 ...