我想尝试获取mac>稳定的>来自此JSON文件的current_version编号:
http://omahaproxy.appspot.com/all.json
操作系统部分位于该部分的顶层,但“通道”值低于版本号。我相信我需要在其中加入一些逻辑来表示类似于:channel = stable,get current_version,但不确定如何读取文件然后向后退去?
答案 0 :(得分:1)
看看这段代码......它将加载页面,获取json信息,然后它将在其中导航并获得current_version
值。
<强>代码:强>
import json
import requests
url = 'http://omahaproxy.appspot.com/all.json'
resp = requests.get(url)
data = json.loads(resp.text)
print(data[0]['versions'][-1]['current_version'])
<强>输出:强>
56.0.2924.87
答案 1 :(得分:1)
这次搜索怎么样? JSON不必有固定的位置。
import json
temp = '[{"os": "win", "versions": [{"branch_commit": "286146d0bce2e2adff52197ca3a87fa7f94ed4bf", "branch_base_position": "455023", "skia_commit": "488f0d674811ae038d34ece9d59c2824ebd4df8f", "v8_version": "5.9.9.0", "previous_version": "59.0.3032.1", "v8_commit": "97674cb813b238739f33a160b20b2dd0f0033af8", "true_branch": "3033", "previous_reldate": "03/06/17", "branch_base_commit": "264668d2881277a13cd9a52c6a26b592b3502fbd", "version": "59.0.3033.1", "current_reldate": "03/07/17", "current_version": "59.0.3033.1", "os": "win", "channel": "canary_asan", "chromium_commit": "286146d0bce2e2adff52197ca3a87fa7f94ed4bf"}, {"branch_commit": "5519d84aa0d42c562cbd4e6871e5caf0d7d4935f", "branch_base_position": "455023", "skia_commit": "488f0d674811ae038d34ece9d59c2824ebd4df8f", "v8_version": "5.9.9.0", "previous_version": "59.0.3032.0", "v8_commit": "97674cb813b238739f33a160b20b2dd0f0033af8", "true_branch": "master", "previous_reldate": "03/06/17", "branch_base_commit": "5519d84aa0d42c562cbd4e6871e5caf0d7d4935f", "version": "59.0.3033.0", "current_reldate": "03/07/17", "current_version": "59.0.3033.0", "os": "win", "channel": "canary", "chromium_commit": "5519d84aa0d42c562cbd4e6871e5caf0d7d4935f"}, {"branch_commit": "db698ced06dd6fb0e583ad8d32bc0a2ef035a907", "branch_base_position": "454471", "skia_commit": "987c2314544c490940a70f00b174059383f9ed6c", "v8_version": "5.8.283.5", "previous_version": "58.0.3026.3", "v8_commit": "99420b633ef2f271cedbb984a26be7d1b0e55ae9", "true_branch": "3029", "previous_reldate": "03/01/17", "branch_base_commit": "939b32ee5ba05c396eef3fd992822fcca9a2e262", "version": "58.0.3029.6", "current_reldate": "03/07/17", "current_version": "58.0.3029.6", "os": "win", "channel": "dev", "chromium_commit": "db698ced06dd6fb0e583ad8d32bc0a2ef035a907"}, {"branch_commit": "53dbc94978a8976f8b84f5c17f9310d8116072d3", "branch_base_position": "444943", "skia_commit": "7695359876b8f90225bc4be895c20f34fcdfaf2e", "v8_version": "5.7.492.60", "previous_version": "57.0.2987.74", "v8_commit": "12b0f188311681aa718755505f8f8c77b2cc487c", "true_branch": "2987", "previous_reldate": "02/22/17", "branch_base_commit": "ad51088c0e8776e8dcd963dbe752c4035ba6dab6", "version": "57.0.2987.88", "current_reldate": "03/01/17", "current_version": "57.0.2987.88", "os": "win", "channel": "beta", "chromium_commit": "53dbc94978a8976f8b84f5c17f9310d8116072d3"}, {"branch_commit": "b169b9a1cc402573843e8c952af14c4e43487e91", "branch_base_position": "433059", "skia_commit": "bf2d9e02d58ea01f1c239f7e2fc024cba140ccb1", "v8_version": "5.6.326.50", "previous_version": "56.0.2924.76", "v8_commit": "d2f8b8429adbc4ddf887fb7e69d89143df07bf08", "true_branch": "2924", "previous_reldate": "01/25/17", "branch_base_commit": "3a87aecc31cd1ffe751dd72c04e5a96a1fc8108a", "version": "56.0.2924.87", "current_reldate": "02/01/17", "current_version": "56.0.2924.87", "os": "win", "channel": "stable", "chromium_commit": "b169b9a1cc402573843e8c952af14c4e43487e91"}]}, {"os": "win64", "versions": [{"branch_commit": "286146d0bce2e2adff52197ca3a87fa7f94ed4bf", "branch_base_position": "455023", "skia_commit": "488f0d674811ae038d34ece9d59c2824ebd4df8f", "v8_version": "5.9.9.0", "previous_version": "59.0.3032.1", "v8_commit": "97674cb813b238739f33a160b20b2dd0f0033af8", "true_branch": "3033", "previous_reldate": "03/06/17", "branch_base_commit": "264668d2881277a13cd9a52c6a26b592b3502fbd", "version": "59.0.3033.1", "current_reldate": "03/07/17", "current_version": "59.0.3033.1", "os": "win64", "channel": "canary_asan", "chromium_commit": "286146d0bce2e2adff52197ca3a87fa7f94ed4bf"}, {"branch_commit": "5519d84aa0d42c562cbd4e6871e5caf0d7d4935f", "branch_base_position": "455023", "skia_commit": "488f0d674811ae038d34ece9d59c2824ebd4df8f", "v8_version": "5.9.9.0", "previous_version": "59.0.3032.0", "v8_commit": "97674cb813b238739f33a160b20b2dd0f0033af8", "true_branch": "master", "previous_reldate": "03/06/17", "branch_base_commit": "5519d84aa0d42c562cbd4e6871e5caf0d7d4935f", "version": "59.0.3033.0", "current_reldate": "03/07/17", "current_version": "59.0.3033.0", "os": "win64", "channel": "canary", "chromium_commit": "5519d84aa0d42c562cbd4e6871e5caf0d7d4935f"}, {"branch_commit": "db698ced06dd6fb0e583ad8d32bc0a2ef035a907", "branch_base_position": "454471", "skia_commit": "987c2314544c490940a70f00b174059383f9ed6c", "v8_version": "5.8.283.5", "previous_version": "58.0.3026.3", "v8_commit": "99420b633ef2f271cedbb984a26be7d1b0e55ae9", "true_branch": "3029", "previous_reldate": "03/01/17", "branch_base_commit": "939b32ee5ba05c396eef3fd992822fcca9a2e262", "version": "58.0.3029.6", "current_reldate": "03/07/17", "current_version": "58.0.3029.6", "os": "win64", "channel": "dev", "chromium_commit": "db698ced06dd6fb0e583ad8d32bc0a2ef035a907"}, {"branch_commit": "53dbc94978a8976f8b84f5c17f9310d8116072d3", "branch_base_position": "444943", "skia_commit": "7695359876b8f90225bc4be895c20f34fcdfaf2e", "v8_version": "5.7.492.60", "previous_version": "57.0.2987.74", "v8_commit": "12b0f188311681aa718755505f8f8c77b2cc487c", "true_branch": "2987", "previous_reldate": "02/22/17", "branch_base_commit": "ad51088c0e8776e8dcd963dbe752c4035ba6dab6", "version": "57.0.2987.88", "current_reldate": "03/01/17", "current_version": "57.0.2987.88", "os": "win64", "channel": "beta", "chromium_commit": "53dbc94978a8976f8b84f5c17f9310d8116072d3"}, {"branch_commit": "b169b9a1cc402573843e8c952af14c4e43487e91", "branch_base_position": "433059", "skia_commit": "bf2d9e02d58ea01f1c239f7e2fc024cba140ccb1", "v8_version": "5.6.326.50", "previous_version": "56.0.2924.76", "v8_commit": "d2f8b8429adbc4ddf887fb7e69d89143df07bf08", "true_branch": "2924", "previous_reldate": "01/25/17", "branch_base_commit": "3a87aecc31cd1ffe751dd72c04e5a96a1fc8108a", "version": "56.0.2924.87", "current_reldate": "02/01/17", "current_version": "56.0.2924.87", "os": "win64", "channel": "stable", "chromium_commit": "b169b9a1cc402573843e8c952af14c4e43487e91"}]}, {"os": "ios", "versions": [{"branch_commit": "N/A", "branch_base_position": "N/A", "v8_version": "N/A", "previous_version": "58.0.3019.0", "true_branch": "N/A", "previous_reldate": "02/22/17", "branch_base_commit": "N/A", "version": "58.0.3025.0", "current_reldate": "03/01/17", "current_version": "58.0.3025.0", "os": "ios", "channel": "dev"}, {"branch_commit": "N/A", "branch_base_position": "N/A", "v8_version": "N/A", "previous_version": "57.0.2987.72", "true_branch": "N/A", "previous_reldate": "02/23/17", "branch_base_commit": "N/A", "version": "57.0.2987.85", "current_reldate": "03/01/17", "current_version": "57.0.2987.85", "os": "ios", "channel": "beta"}, {"branch_commit": "N/A", "branch_base_position": "N/A", "v8_version": "N/A", "previous_version": "55.0.2883.79", "true_branch": "N/A", "previous_reldate": "12/06/16", "branch_base_commit": "N/A", "version": "56.0.2924.79", "current_reldate": "02/01/17", "current_version": "56.0.2924.79", "os": "ios", "channel": "stable"}]}, {"os": "cros", "versions": [{"branch_commit": "1c6c16dbf07ea981278e749d8d2c0a0334c23468", "branch_base_position": "453800", "skia_commit": "32f2818c9d10090efeea62ccc211d48a33322dfb", "v8_version": "5.8.297.0", "previous_version": "58.0.3021.3", "v8_commit": "03d03326a57b940fc386775d3efe1f33525c4f2d", "true_branch": "master", "previous_reldate": "02/28/17", "branch_base_commit": "1c6c16dbf07ea981278e749d8d2c0a0334c23468", "version": "58.0.3027.0", "current_reldate": "03/03/17", "current_version": "58.0.3027.0", "os": "cros", "channel": "dev", "chromium_commit": "1c6c16dbf07ea981278e749d8d2c0a0334c23468"}, {"branch_commit": "cc67fc9c47ea90a1a4e06db496a54da33dbcd626", "branch_base_position": "444943", "skia_commit": "7695359876b8f90225bc4be895c20f34fcdfaf2e", "v8_version": "5.7.492.59", "previous_version": "57.0.2987.75", "v8_commit": "364aeed9926a5a5e49d3020fcdb7fce684cbd601", "true_branch": "2987", "previous_reldate": "02/24/17", "branch_base_commit": "ad51088c0e8776e8dcd963dbe752c4035ba6dab6", "version": "57.0.2987.85", "current_reldate": "03/02/17", "current_version": "57.0.2987.85", "os": "cros", "channel": "beta", "chromium_commit": "cc67fc9c47ea90a1a4e06db496a54da33dbcd626"}, {"branch_commit": "0de3ff31100da107a295e1fbf16e44a5effbea15", "branch_base_position": "433059", "skia_commit": "dd45f8195783efc7b8044b006eae5ea5ac127cc2", "v8_version": "5.6.326.55", "previous_version": "56.0.2924.101", "v8_commit": "93947afa548945132d5069544f881257d36df5f8", "true_branch": "2924", "previous_reldate": "02/18/17", "branch_base_commit": "3a87aecc31cd1ffe751dd72c04e5a96a1fc8108a", "version": "56.0.2924.110", "current_reldate": "02/24/17", "current_version": "56.0.2924.110", "os": "cros", "channel": "stable", "chromium_commit": "0de3ff31100da107a295e1fbf16e44a5effbea15"}]}, {"os": "mac", "versions": [{"branch_commit": "315770b2c801b703c162da3386e014d663b7deae", "branch_base_position": "455383", "skia_commit": "27bece831ddecfd33ee5fecd81ca9e6939b30e49", "v8_version": "5.9.26.0", "previous_version": "59.0.3034.0", "v8_commit": "b42fea0f3d1f07669a4e71cff88fc0b2bc449669", "true_branch": "master", "previous_reldate": "03/08/17", "branch_base_commit": "315770b2c801b703c162da3386e014d663b7deae", "version": "59.0.3035.0", "current_reldate": "03/08/17", "current_version": "59.0.3035.0", "os": "mac", "channel": "canary", "chromium_commit": "315770b2c801b703c162da3386e014d663b7deae"}, {"branch_commit": "db698ced06dd6fb0e583ad8d32bc0a2ef035a907", "branch_base_position": "454471", "skia_commit": "987c2314544c490940a70f00b174059383f9ed6c", "v8_version": "5.8.283.5", "previous_version": "58.0.3026.3", "v8_commit": "99420b633ef2f271cedbb984a26be7d1b0e55ae9", "true_branch": "3029", "previous_reldate": "03/01/17", "branch_base_commit": "939b32ee5ba05c396eef3fd992822fcca9a2e262", "version": "58.0.3029.6", "current_reldate": "03/07/17", "current_version": "58.0.3029.6", "os": "mac", "channel": "dev", "chromium_commit": "db698ced06dd6fb0e583ad8d32bc0a2ef035a907"}, {"branch_commit": "53dbc94978a8976f8b84f5c17f9310d8116072d3", "branch_base_position": "444943", "skia_commit": "7695359876b8f90225bc4be895c20f34fcdfaf2e", "v8_version": "5.7.492.60", "previous_version": "57.0.2987.74", "v8_commit": "12b0f188311681aa718755505f8f8c77b2cc487c", "true_branch": "2987", "previous_reldate": "02/22/17", "branch_base_commit": "ad51088c0e8776e8dcd963dbe752c4035ba6dab6", "version": "57.0.2987.88", "current_reldate": "03/01/17", "current_version": "57.0.2987.88", "os": "mac", "channel": "beta", "chromium_commit": "53dbc94978a8976f8b84f5c17f9310d8116072d3"}, {"branch_commit": "b169b9a1cc402573843e8c952af14c4e43487e91", "branch_base_position": "433059", "skia_commit": "bf2d9e02d58ea01f1c239f7e2fc024cba140ccb1", "v8_version": "5.6.326.50", "previous_version": "56.0.2924.76", "v8_commit": "d2f8b8429adbc4ddf887fb7e69d89143df07bf08", "true_branch": "2924", "previous_reldate": "01/25/17", "branch_base_commit": "3a87aecc31cd1ffe751dd72c04e5a96a1fc8108a", "version": "56.0.2924.87", "current_reldate": "02/01/17", "current_version": "56.0.2924.87", "os": "mac", "channel": "stable", "chromium_commit": "b169b9a1cc402573843e8c952af14c4e43487e91"}]}, {"os": "linux", "versions": [{"branch_commit": "db698ced06dd6fb0e583ad8d32bc0a2ef035a907", "branch_base_position": "454471", "skia_commit": "987c2314544c490940a70f00b174059383f9ed6c", "v8_version": "5.8.283.5", "previous_version": "58.0.3026.3", "v8_commit": "99420b633ef2f271cedbb984a26be7d1b0e55ae9", "true_branch": "3029", "previous_reldate": "03/01/17", "branch_base_commit": "939b32ee5ba05c396eef3fd992822fcca9a2e262", "version": "58.0.3029.6", "current_reldate": "03/07/17", "current_version": "58.0.3029.6", "os": "linux", "channel": "dev", "chromium_commit": "db698ced06dd6fb0e583ad8d32bc0a2ef035a907"}, {"branch_commit": "53dbc94978a8976f8b84f5c17f9310d8116072d3", "branch_base_position": "444943", "skia_commit": "7695359876b8f90225bc4be895c20f34fcdfaf2e", "v8_version": "5.7.492.60", "previous_version": "57.0.2987.74", "v8_commit": "12b0f188311681aa718755505f8f8c77b2cc487c", "true_branch": "2987", "previous_reldate": "03/02/17", "branch_base_commit": "ad51088c0e8776e8dcd963dbe752c4035ba6dab6", "version": "57.0.2987.88", "current_reldate": "03/02/17", "current_version": "57.0.2987.88", "os": "linux", "channel": "beta", "chromium_commit": "53dbc94978a8976f8b84f5c17f9310d8116072d3"}, {"branch_commit": "b169b9a1cc402573843e8c952af14c4e43487e91", "branch_base_position": "433059", "skia_commit": "bf2d9e02d58ea01f1c239f7e2fc024cba140ccb1", "v8_version": "5.6.326.50", "previous_version": "56.0.2924.76", "v8_commit": "d2f8b8429adbc4ddf887fb7e69d89143df07bf08", "true_branch": "2924", "previous_reldate": "01/25/17", "branch_base_commit": "3a87aecc31cd1ffe751dd72c04e5a96a1fc8108a", "version": "56.0.2924.87", "current_reldate": "02/02/17", "current_version": "56.0.2924.87", "os": "linux", "channel": "stable", "chromium_commit": "b169b9a1cc402573843e8c952af14c4e43487e91"}]}, {"os": "android", "versions": [{"branch_commit": "c0f3168c4a18342efc1939b16b52a6befc966e5b", "branch_base_position": "454806", "skia_commit": "fc75b5afdef9bf896e20de9e88ca99f336616559", "v8_version": "5.9.5.0", "previous_version": "58.0.3029.3", "v8_commit": "60617ee5d1815677b0aeb7321390b635f6be902e", "true_branch": "master", "previous_reldate": "03/04/17", "branch_base_commit": "c0f3168c4a18342efc1939b16b52a6befc966e5b", "version": "59.0.3032.0", "current_reldate": "03/06/17", "current_version": "59.0.3032.0", "os": "android", "channel": "canary", "chromium_commit": "c0f3168c4a18342efc1939b16b52a6befc966e5b"}, {"branch_commit": "40c6ce8d2a4780f124933d2a8de1199abc527ee5", "branch_base_position": "453454", "skia_commit": "edbeb8b842aa86d18388f75a1dbf1e470a565680", "v8_version": "5.8.293.0", "previous_version": "58.0.3019.3", "v8_commit": "d678037326492171f04895ffb360e16e5248182a", "true_branch": "3026", "previous_reldate": "02/22/17", "branch_base_commit": "fe586ab75aca1b8ab839db23bceac5f621389fed", "version": "58.0.3026.5", "current_reldate": "03/02/17", "current_version": "58.0.3026.5", "os": "android", "channel": "dev", "chromium_commit": "40c6ce8d2a4780f124933d2a8de1199abc527ee5"}, {"branch_commit": "53dbc94978a8976f8b84f5c17f9310d8116072d3", "branch_base_position": "444943", "skia_commit": "7695359876b8f90225bc4be895c20f34fcdfaf2e", "v8_version": "5.7.492.60", "previous_version": "57.0.2987.74", "v8_commit": "12b0f188311681aa718755505f8f8c77b2cc487c", "true_branch": "2987", "previous_reldate": "02/23/17", "branch_base_commit": "ad51088c0e8776e8dcd963dbe752c4035ba6dab6", "version": "57.0.2987.88", "current_reldate": "03/02/17", "current_version": "57.0.2987.88", "os": "android", "channel": "beta", "chromium_commit": "53dbc94978a8976f8b84f5c17f9310d8116072d3"}, {"branch_commit": "b169b9a1cc402573843e8c952af14c4e43487e91", "branch_base_position": "433059", "skia_commit": "bf2d9e02d58ea01f1c239f7e2fc024cba140ccb1", "v8_version": "5.6.326.50", "previous_version": "55.0.2883.91", "v8_commit": "d2f8b8429adbc4ddf887fb7e69d89143df07bf08", "true_branch": "2924", "previous_reldate": "12/09/16", "branch_base_commit": "3a87aecc31cd1ffe751dd72c04e5a96a1fc8108a", "version": "56.0.2924.87", "current_reldate": "02/02/17", "current_version": "56.0.2924.87", "os": "android", "channel": "stable", "chromium_commit": "b169b9a1cc402573843e8c952af14c4e43487e91"}]}, {"os": "webview", "versions": [{"branch_commit": "40c6ce8d2a4780f124933d2a8de1199abc527ee5", "branch_base_position": "453454", "skia_commit": "edbeb8b842aa86d18388f75a1dbf1e470a565680", "v8_version": "5.8.293.0", "previous_version": "58.0.3019.3", "v8_commit": "d678037326492171f04895ffb360e16e5248182a", "true_branch": "3026", "previous_reldate": "02/22/17", "branch_base_commit": "fe586ab75aca1b8ab839db23bceac5f621389fed", "version": "58.0.3026.5", "current_reldate": "03/02/17", "current_version": "58.0.3026.5", "os": "webview", "channel": "dev", "chromium_commit": "40c6ce8d2a4780f124933d2a8de1199abc527ee5"}, {"branch_commit": "53dbc94978a8976f8b84f5c17f9310d8116072d3", "branch_base_position": "444943", "skia_commit": "7695359876b8f90225bc4be895c20f34fcdfaf2e", "v8_version": "5.7.492.60", "previous_version": "57.0.2987.74", "v8_commit": "12b0f188311681aa718755505f8f8c77b2cc487c", "true_branch": "2987", "previous_reldate": "02/23/17", "branch_base_commit": "ad51088c0e8776e8dcd963dbe752c4035ba6dab6", "version": "57.0.2987.88", "current_reldate": "03/02/17", "current_version": "57.0.2987.88", "os": "webview", "channel": "beta", "chromium_commit": "53dbc94978a8976f8b84f5c17f9310d8116072d3"}, {"branch_commit": "b169b9a1cc402573843e8c952af14c4e43487e91", "branch_base_position": "433059", "skia_commit": "bf2d9e02d58ea01f1c239f7e2fc024cba140ccb1", "v8_version": "5.6.326.50", "previous_version": "56.0.2924.78", "v8_commit": "d2f8b8429adbc4ddf887fb7e69d89143df07bf08", "true_branch": "2924", "previous_reldate": "01/26/17", "branch_base_commit": "3a87aecc31cd1ffe751dd72c04e5a96a1fc8108a", "version": "56.0.2924.87", "current_reldate": "02/02/17", "current_version": "56.0.2924.87", "os": "webview", "channel": "stable", "chromium_commit": "b169b9a1cc402573843e8c952af14c4e43487e91"}]}]'
dictionary = json.loads(temp)
for each in dictionary:
if each.get("os") == "mac":
versions = each.get("versions")
for version in versions:
if version.get("channel") == "stable":
print (version.get("current_version"))
<强>输出:强>
56.0.2924.87