Python 处理iOS ipa文件里面的.plist

前言

在用python做脚本的时候,需要操作到iOS打包出来的ipa文件的plist文件。

解决方案

第三方库:plistlib 插件

1、先写入本地再读取

  # 读写文件
  fp = open("1.plist", 'w')
  # 直接写入字符串
  fp.write(str(uploadresult))
  fp.close()

  #  通过文件名路径读取文件     
  plistlib.readPlist({文件路径以及文件名})

2、直接读取

 /// 直接读取内容
  pl = plistlib.readPlistFromBytes(str(uploadresult).encode())
  /// 输出相关结果
  print(pl[key])

附注

plist文件内容格式:


<plist version="1.0">
<dict>
    <key>$PATHkey>
    <string>/Users/Demo/Python/PythonCollection/venv/bin:/Users/lvchenqiang/.rvm/gems/ruby-2.4.0/bin:/Users/.rvm/gems/ruby-2.4.0@global/bin:/Users//.rvm/rubies/ruby-2.4.0/bin:/usr/local/bin:/usr/bin:/bin:/usr/sbin:/sbin:/Users/lvchenqiang/.rvm/bin:/Users/Work/SourceTree/venv/binstring>
    <key>dev-tools-infokey>
    <dict>
        <key>search-methodkey>
        <integer>-1integer>
    dict>
    <key>os-versionkey>
    <string>10.13.3string>
    <key>product-errorskey>
    <array>
        <dict>
            <key>codekey>
            <integer>-22910integer>
            <key>messagekey>
            <string>Please sign in with an app-specific password. You can create one at appleid.apple.com.string>
            <key>userInfokey>
            <dict>
                <key>NSLocalizedDescriptionkey>
                <string>Please sign in with an app-specific password. You can create one at appleid.apple.com.string>
                <key>NSLocalizedFailureReasonkey>
                <string>Unable to validate your application.string>
            dict>
        dict>
    array>
    <key>tool-pathkey>
    <string>/Applications/Xcode.app/Contents/Applications/Application Loader.app/Contents/Frameworks/ITunesSoftwareService.frameworkstring>
    <key>tool-versionkey>
    <string>1.13.810string>
dict>
plist>

你可能感兴趣的:(Python)