Python obtains the URL address of an apk file.

Source: Internet
Author: User
A friend who needs to extract the specific URL of the apk file can look at this code instance. In work, you often need to extract the specific URL of the apk file. if you want to use a Python script for automatic processing.
The basic knowledge of Python is as follows:
OS. walk ()
Function declaration: OS. walk (top, topdown = True, onerror = None)
(1) The top parameter indicates the path of the top-level directory to be traversed.
(2) the default value of the topdown parameter is "True", indicating that the files under the top-level directory are returned first, and then the files in the subdirectories are traversed. If the value of topdown is "False", the system first traverses the files in the subdirectory and then returns the files in the top-level Directory.
(3) the onerror parameter defaults to "None", indicating that the file duration error is ignored. If it is not empty, a user-defined function will be provided with an error message to continue traversal or throw an exception to stop traversal.
Returned value: the function returns a triple containing three elements. These three elements are: the path name for each traversal, the subdirectory list under the path, and the file list under the Directory.
OS. walk instance: Delete a folder (you can delete it by using the recursive call of OS. listdir)

The code is as follows:


#! /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)

# Call
Remove_dir (r "C: \ Users \ Administrator \ Desktop \ abc ")


Python: OS. system (), OS. popen (), commands. getstatusoutput ()
OS. system () cannot obtain the output and return values;
The OS. popen () returns the object of file read. The read () operation on the object shows the output, but the returned value is not obtained.
The return value and output can be obtained through the commands. getstatusoutput () method.
(Status, output) = commands. getstatusoutput ('cat/proc/cpuinfo ')
3. The contains (...) function of the operator module in Python
Contains (a, B) -- Same as B in a (note reversed operands). determine whether B is contained by
After the basic knowledge is introduced, you can go to the code:

The code is as follows:


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 ()
# Search for URLs by row
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
# Obtain command execution results and return values
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 =''

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.