如何从json.loads()字典中获取值?

Posted

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了如何从json.loads()字典中获取值?相关的知识,希望对你有一定的参考价值。

我正在执行一个网络抓取项目,以从一家就餐场所获取所有餐馆。我正在根据另一个用户的建议向网站发送XHR请求,以获取页面的javascript。但是,我尝试了几种方法,但似乎无法从json字典中获取值。我的代码如下:

import requests
import json

myProxy = 
            "http"  : "http://10.120.118.49:8080",
            "https"  : "https://10.120.118.49:8080"
            

data = "cacheKey": "JTdCJTIyYWRkcmVzcyUyMiUzQSUyMkxvbmRvbiUyMEV5ZSUyMiUyQyUyMnJlZmVyZW5jZSUyMiUzQSUyMkNoSUpjMm5TQUxrRWRrZ1JrdW9KSkJmemtVSSUyMiUyQyUyMnJlZmVyZW5jZVR5cGUlMjIlM0ElMjJnb29nbGVfcGxhY2VzJTIyJTJDJTIybGF0aXR1ZGUlMjIlM0E1MS41MDMxMDE1JTJDJTIybG9uZ2l0dWRlJTIyJTNBLTAuMTE3NDcyNzk5OTk5OTk5OTklN0Q=/DELIVERY///0/0//JTVCJTVE/",
        "feedSessionCount": "announcementCount": 0, "announcementLabel": "", "userQuery": "", "date": "", "startTime": 0, "endTime": 0, "carouselId": "", "sortAndFilters": []


headers = 
    "x-csrf-token": "x",
    'cookie': "uev2.id.xp=84c25cae-9049-4ed7-8119-b00e21bd099b; dId=f14e51e4-f3af-4da8-9cbd-f0f0024fa575; uev2.id.session=3c486ded-ffc4-4dfc-9a4e-849fa25afee4; uev2.ts.session=1583939016969; jwt-session=eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJpYXQiOjE1ODM5MzkwMTcsImV4cCI6MTU4NDAyNTQxN30.7-3tQOFimBd2up8wv94GsJacTnk4x1Cm498ZITSy71w; uev2.loc=%7B%22address%22%3A%7B%22address1%22%3A%22London%20Eye%22%2C%22address2%22%3A%22The%20Queen's%20Walk%2C%20South%20Bank%2C%20London%22%2C%22aptOrSuite%22%3A%22%22%2C%22city%22%3A%22%22%2C%22country%22%3A%22%22%2C%22eaterFormattedAddress%22%3A%22The%20Queen's%20Walk%2C%20South%20Bank%2C%20London%20SE1%207PB%2C%20UK%22%2C%22postalCode%22%3A%22%22%2C%22region%22%3A%22%22%2C%22subtitle%22%3A%22The%20Queen's%20Walk%2C%20South%20Bank%2C%20London%22%2C%22title%22%3A%22London%20Eye%22%2C%22uuid%22%3A%22%22%7D%2C%22latitude%22%3A51.503095699999996%2C%22longitude%22%3A-0.11750189999999999%2C%22reference%22%3A%22ChIJc2nSALkEdkgRkuoJJBfzkUI%22%2C%22referenceType%22%3A%22google_places%22%2C%22type%22%3A%22google_places%22%2C%22source%22%3A%22rev_geo_reference%22%7D; marketing_vistor_id=1cdd05e4-e3ea-40e3-a2d9-b8c790ba7b70; utag_main=v_id:0170ca1f682600a0ff2795e620200104e014200d00978$_sn:1$_se:6$_ss:0$_st:1583940871143$ses_id:1583939020843%3Bexp-session$_pn:3%3Bexp-session; _userUuid=; _gcl_au=1.1.1208413337.1583939021; QSI_HistorySession=https%3A%2F%2Fwww.ubereats.com%2Fen-US%2Ffeed%2F%3Fpl%3DJTdCJTIyYWRkcmVzcyUyMiUzQSUyMkxvbmRvbiUyMEV5ZSUyMiUyQyUyMnJlZmVyZW5jZSUyMiUzQSUyMkNoSUpjMm5TQUxrRWRrZ1JrdW9KSkJmemtVSSUyMiUyQyUyMnJlZmVyZW5jZVR5cGUlMjIlM0ElMjJnb29nbGVfcGxhY2VzJTIyJTJDJTIybGF0aXR1ZGUlMjIlM0E1MS41MDMxMDE1JTJDJTIybG9uZ2l0dWRlJTIyJTNBLTAuMTE3NDcyNzk5OTk5OTk5OTklN0Q%253D~1583939021598%7Chttps%3A%2F%2Fwww.ubereats.com%2Fen-US%2Ffeed%2F%3Fpl%3DJTdCJTIyYWRkcmVzcyUyMiUzQSUyMkxvbmRvbiUyMEV5ZSUyMiUyQyUyMnJlZmVyZW5jZSUyMiUzQSUyMkNoSUpjMm5TQUxrRWRrZ1JrdW9KSkJmemtVSSUyMiUyQyUyMnJlZmVyZW5jZVR5cGUlMjIlM0ElMjJnb29nbGVfcGxhY2VzJTIyJTJDJTIybGF0aXR1ZGUlMjIlM0E1MS41MDMxMDE1JTJDJTIybG9uZ2l0dWRlJTIyJTNBLTAuMTE3NDcyNzk5OTk5OTk5OTklN0Q%3D~1583939068750; _ga=GA1.2.455546941.1583939022; _gid=GA1.2.1252191334.1583939022; _fbp=fb.1.1583939022805.1654600085; _scid=0c232be0-9f0e-4e0e-a335-f92c9fa7f1f0; _sctr=1|1583877600000"


r = requests.post(
    "https://www.ubereats.com/api/getFeedV1?localeCode=en-US", json=data, headers=headers, proxies=myProxy).json()


circ=json.dumps(r)

new_circ=json.loads(circ)

我已经尝试使用类似dict_key=['title']的方法,但是它总是会检索到错误。

json代码如下:

'status': 'success', 'data': 'billboards': [], 'countdowns': [], 'diningModes': ['mode': 'DELIVERY', 'title': 'Delivery', 'isAvailable': True, 'isSelected': True, 'mode': 'PICKUP', 'title': 'Pickup', 'isAvailable': True, 'isSelected': False], 'sortAndFilters': ['uuid': '1c7cf7ef-730f-431f-9072-26bc39f7c021', 'options': ['uuid': '3c7cf7ef-730f-431f-9072-26bc39f7c022', 'value': 'Recommended', 'isDefault': True, 'selected': True, 'uuid': '4c7cf7ef-730f-431f-9072-26bc39f7c023', 'value': 'Most popular', 'isDefault': False, 'selected': False, 'uuid': '5c7cf7ef-730f-431f-9072-26bc39f7c024', 'value': 'Delivery time', 'isDefault': False, 'selected': False], 'minPermitted': 1, 'maxPermitted': 1, 'type': 'sort', 'badge': 'textFormat': '<span>Sort</span>', 'selected': False, 'uuid': '2c7cf7ef-730f-431f-9072-46bc39f7c021', 'options': ['uuid': '2c7cf7ef-730f-431f-9072-26bc39f7c032', 'value': '$', 'isDefault': False, 'selected': False, 'uuid': '2c7cf7ef-730f-431f-9072-26bc39f7c033', 'value': '$$', 'isDefault': False, 'selected': False, 'uuid': '2c7cf7ef-730f-431f-9072-26bc39f7c034', 'value': '$$$', 'isDefault': False, 'selected': False, 'uuid': '2c7cf7ef-730f-431f-9072-26bc39f7c035', 'value': '$$$$', 'isDefault': False, 'selected': False], 'minPermitted': 0, 'maxPermitted': 4, 'type': 'priceRangeFilter', 'badge': 'textFormat': '<span>Price Range</span>', 'selected': False, 'uuid': '2c7cf7ef-730f-431f-9072-36bc39f7c122', 'options': ['uuid': '2c7cf7ef-730f-431f-9072-26bc39f7c222', 'value': 'Vegetarian-Friendly', 'isDefault': False, 'selected': False, 'uuid': '2c7cf7ef-730f-431f-9072-26bc39f7c322', 'value': 'Vegan-Friendly', 'isDefault': False, 'selected': False, 'uuid': '2c7cf7ef-730f-431f-9072-26bc39f7c422', 'value': 'Gluten-Free Friendly', 'isDefault': False, 'selected': False, 'uuid': '1d039016-066c-49a9-86df-319cbefa1ddf', 'value': 'Allergy Friendly', 'isDefault': False, 'selected': False], 'minPermitted': 0, 'maxPermitted': 4, 'type': 'dietaryFilter', 'badge': 'textFormat': '<span>Dietary</span>', 'selected': False], 'favorites': , 'feedItems': ['uuid': 'ed30095e-d6be-11e6-99aa-a45e60e89c49', 'type': 'STORE_CAROUSEL', 'stores': ['uuid': '83dea20d-6f25-48e1-b4bc-283c0ab14034', 'trackingCode': '"uuid":"3ef8a804-b3d3-4dae-86b2-b19b49e65771","codeType":"STORE","metaInfo":"pluginName":"recommendationFeedPlugin","analyticsLabel":"top_stores_by_city_v2","storePayload":"storeUUID":"83dea20d-6f25-48e1-b4bc-283c0ab14034","isOrderable":true,"score":"total":0,"etdInfo":"dropoffETARange":"min":10,"max":20,"raw":15,"fareInfo":"multiplier":1', 'uuid': 'b2f77c0d-d364-4707-b8d4-e1c275be85d7', 'trackingCode': '"uuid":"f112e5c7-6977-4500-9494-703438066486","codeType":"STORE","metaInfo":"pluginName":"recommendationFeedPlugin","analyticsLabel":"top_stores_by_city_v2","storePayload":"storeUUID":"b2f77c0d-d364-4707-b8d4-e1c275be85d7","isOrderable":true,"score":"total":0,"etdInfo":"dropoffETARange":"min":15,"max":25,"raw":20,"fareInfo":"multiplier":1', 'uuid': '9db7b92e-5691-44ad-84b6-3b11e09e3029', 'trackingCode': '"uuid":"eb4b402a-8bf4-420c-981d-f960f7b0506a","codeType":"STORE","metaInfo":"pluginName":"recommendationFeedPlugin","analyticsLabel":"top_stores_by_city_v2","storePayload":"storeUUID":"9db7b92e-5691-44ad-84b6-3b11e09e3029","isOrderable":true,"score":"total":0,"etdInfo":"dropoffETARange":"min":30,"max":40,"raw":35,"fareInfo":"multiplier":1', 'uuid': '62135728-318b-4338-9f8e-1022a40a20cb', 'trackingCode': '"uuid":"9dd542bb-63de-409c-83db-3196d4ca9559","codeType":"STORE","metaInfo":"pluginName":"recommendationFeedPlugin","analyticsLabel":"top_stores_by_city_v2","storePayload":"storeUUID":"62135728-318b-4338-9f8e-1022a40a20cb","isOrderable":true,"score":"total":0,"etdInfo":"dropoffETARange":"min":20,"max":30,"raw":25,"fareInfo":"multiplier":1', 'uuid': 'b1a60c2a-62e6-447d-ade8-c70f040e9f34', 'trackingCode': '"uuid":"9c72ac2a-39af-46ea-8bae-1de19b2e0725","codeType":"STORE","metaInfo":"pluginName":"recommendationFeedPlugin","analyticsLabel":"top_stores_by_city_v2","storePayload":"storeUUID":"b1a60c2a-62e6-447d-ade8-c70f040e9f34","isOrderable":true,"score":"total":0,"etdInfo":"dropoffETARange":"min":5,"max":15,"raw":10,"fareInfo":"multiplier":1', 'uuid': 'f5273827-c155-439b-80b6-374e31a447b5', 'trackingCode': '"uuid":"f7df926f-1966-490a-aaa8-915c253ccb39","codeType":"STORE","metaInfo":"pluginName":"recommendationFeedPlugin","analyticsLabel":"top_stores_by_city_v2","storePayload":"storeUUID":"f5273827-c155-439b-80b6-374e31a447b5","isOrderable":true,"score":"total":0,"etdInfo":"dropoffETARange":"min":15,"max":25,"raw":20,"fareInfo":"multiplier":1'], 'title': 'Popular Near You', 'subtitle': '', 'carouselId': 'eyJwbHVnaW4iOiJyZWNvbW1lbmRhdGlvbkZlZWRQbHVnaW4iLCJyZWNvbW1UeXBlIjoidG9wX3N0b3Jlc19ieV9jaXR5X3YyIn0=', 'uuid': 'a22c790f-fe2a-4fa2-b269-a2600520ef70', 'type': 'STORE_CAROUSEL', 'stores': ['uuid': '6ba9f21e-f739-4c34-a27b-b56ac2f1b9c9', 'trackingCode': '"uuid":"31f7fea0-31af-44d1-af87-1b1938d0a58a","codeType":"STORE","metaInfo":"pluginName":"promotionFeedPlugin","analyticsLabel":"promoted_restaurants","storePayload":"storeUUID":"6ba9f21e-f739-4c34-a27b-b56ac2f1b9c9","isOrderable":true,"score":"total":0,"etdInfo":"dropoffETARange":"min":25,"max":35,"raw":30,"fareInfo":"multiplier":1', 'uuid': '10ef3669-1bb4-4907-9500-3eb9172db368', 'trackingCode': '"uuid":"0eb2a33d-62d0-49d1-8d5c-386c703431a8","codeType":"STORE","metaInfo":"pluginName":"promotionFeedPlugin","analyticsLabel":"promoted_restaurants","storePayload":"storeUUID":"10ef3669-1bb4-4907-9500-3eb9172db368","isOrderable":true,"score":"total":0,"etdInfo":"dropoffETARange":"min":25,"max":35,"raw":30,"fareInfo":"multiplier":1', 'uuid': '73a648b8-486f-408e-8b96-ee0dfa63e16e', 'trackingCode': '"uuid":"8c2e693d-988e-4db1-8ebb-10a038b905eb","codeType":"STORE","metaInfo":"pluginName":"promotionFeedPlugin","analyticsLabel":"promoted_restaurants","storePayload":"storeUUID":"73a648b8-486f-408e-8b96-ee0dfa63e16e","isOrderable":true,"score":"total":0,"etdInfo":"dropoffETARange":"min":25,"max":35,"raw":30,"fareInfo":"multiplier":1', 'uuid': '4e348f2e-5130-42d8-b302-7ed0012d5707', 'trackingCode': '"uuid":"097faec4-9684-4307-8067-b79088c21cba","codeType":"STORE","metaInfo":"pluginName":"promotionFeedPlugin","analyticsLabel":"promoted_restaurants","storePayload":"storeUUID":"4e348f2e-5130-42d8-b302-7ed0012d5707","isOrderable":true,"score":"total":0,"etdInfo":"dropoffETARange":"min":20,"max":30,"raw":25,"fareInfo":"multiplier":1', 'uuid': 'ff4a2fca-f48a-4ad8-9368-b8612f7bd199', 'trackingCode': '"uuid":"8451bcf5-e12e-417a-be16-df312127d815","codeType":"STORE","metaInfo":"pluginName":"promotionFeedPlugin","analyticsLabel":"promoted_restaurants","storePayload":"storeUUID":"ff4a2fca-f48a-4ad8-9368-b8612f7bd199","isOrderable":true,"score":"total":0,"etdInfo":"dropoffETARange":"min":25,"max":35,"raw":30,"fareInfo":"multiplier":1', 'uuid': '315b931c-1e26-4cdd-913b-3220092df6fd', 'trackingCode': '"uuid":"363322dd-f66e-4478-93ce-6a8ad10edd17","codeType":"STORE","metaInfo":"pluginName":"promotionFeedPlugin","analyticsLabel":"promoted_restaurants","storePayload":"storeUUID":"315b931c-1e26-4cdd-913b-3220092df6fd","isOrderable":true,"score":"total":0,"etdInfo":"dropoffETARange":"min":35,"max":45,"raw":40,"fareInfo":"multiplier":1'], 'title': "Don't miss these deals", 'subtitle': 'Limited availability', 'carouselId': 'eyJyZWNvbW1UeXBlIjoicHJvbW90ZWRfcmVzdGF1cmFudHMiLCJwbHVnaW4iOiJyZWNvbW1lbmRhdGlvbkZlZWRQbHVnaW4ifQ==', 'title': 'Looking for something else?', 'uuid': '20354d7a-e4fe-47af-8ff6-187bca92f3f9', 'type': 'CUISINE_CAROUSEL', 'items': ['title': 'Fast Food', 'categoryName': 'Fast Food', 'slug': 'fast-food', 'imageUrl': 'https://duyt4h9nfnj50.cloudfront.net/sku/f6e04e64903c3207e68c649e24cc2f32', 'trackingCode': '"uuid":"a8e66432-0715-4de2-afb1-8d3eeb401a00","codeType":"SEARCH","metaInfo":"pluginName":"search","analyticsLabel":"searchHome","searchPayload":"term":"Fast Food","searchHomeSection":"Top Categories"', 'title': 'Pizza', 'categoryName': 'Pizza', 'slug': 'pizza', 'imageUrl': 'https://duyt4h9nfnj50.cloudfront.net/sku/971d80f9ccce0c8eab98014650ee97eb', 'trackingCode': '"uuid":"ad402960-f225-42b5-9f90-8178cf09f61c","codeType":"SEARCH","metaInfo":"pluginName":"search","analyticsLabel":"searchHome","searchPayload":"term":"Pizza","searchHomeSection":"Top Categories"', 'title': 'Breakfast and Brunch', 'categoryName': 'Breakfast and Brunch', 'slug': 'breakfast-and-brunch', 'imageUrl': 'https://duyt4h9nfnj50.cloudfront.net/sku/0bc9ca19a02e3bd03f2395c8cf8a3e0c', 'trackingCode': '"uuid":"f4e3f7f6-244c-4a69-8a47-56463383367b","codeType":"SEARCH","metaInfo":"pluginName":"search","analyticsLabel":"searchHome","searchPayload":"term":"Breakfast and Brunch","searchHomeSection":"Top Categories"', 'title': 'Burgers', 'categoryName': 'Burgers', 'slug': 'burgers', 'imageUrl': 'https://duyt4h9nfnj50.cloudfront.net/sku/128411a1b54acd3c3c4e5263e7c58e2d', 'trackingCode': '"uuid":"c90cc579-bc75-4239-8f04-e78c49fd3434","codeType":"SEARCH","metaInfo":"pluginName":"search","analyticsLabel":"searchHome","searchPayload":"term":"Burgers","searchHomeSection":"Top Categories"', 'title': 'Chinese', 'categoryName': 'Chinese', 'slug': 'chinese', 'imageUrl': 'https://duyt4h9nfnj50.cloudfront.net/sku/a84dc69cee307fba4f559b1e825d8e9e', 'trackingCode': '"uuid":"b215f5a9-2b38-468a-9b7a-c205b0d46f25","codeType":"SEARCH","metaInfo":"pluginName":"search","analyticsLabel":"searchHome","searchPayload":"term":"Chinese","searchHomeSection":"Top Categories"', 'title': 'Indian', 'categoryName': 'Indian', 'slug': 'indian', 'imageUrl': 'https://duyt4h9nfnj50.cloudfront.net/sku/836fa3b8cf098f8cbed99cedc7c06779', 'trackingCode': '"uuid":"aa180f06-2487-4b52-b71a-dd8de218ed8b","codeType":"SEARCH","metaInfo":"pluginName":"search","analyticsLabel":"searchHome","searchPayload":"term":"Indian","searchHomeSection":"Top Categories"', 'title': 'Desserts', 'categoryName': 'Desserts', 'slug': 'desserts', 'imageUrl': 'https://duyt4h9nfnj50.cloudfront.net/sku/3962b16c350438a56fd7794ba4a15b9c', 'trackingCode': '"uuid":"808641c4-af64-4e00-a746-c3e08dffee22","codeType":"SEARCH","metaInfo":"pluginName":"search","analyticsLabel":"searchHome","searchPayload":"term":"Desserts","searchHomeSection":"Top Categories"', 'title': 'Halal', 'categoryName': 'Halal', 'slug': 'halal', 'imageUrl': 'https://duyt4h9nfnj50.cloudfront.net/sku/14707f344282ab7f8b5d7c471128d910', 'trackingCode': '"uuid":"df9af43e-b341-4d90-abb7-8a7d63599ca6","codeType":"SEARCH","metaInfo":"pluginName":"search","analyticsLabel":"searchHome","searchPayload":"term":"Halal","searchHomeSection":"Top Categories"', 'title': 'Healthy', 'categoryName': 'Healthy', 'slug': 'healthy', 'imageUrl': 'https://duyt4h9nfnj50.cloudfront.net/sku/5bcce6114b9d2d5a39b81e756a250407', 'trackingCode': '"uuid":"2cf9034d-dd02-4c46-bd7c-6727f5fa8d84","codeType":"SEARCH","metaInfo":"pluginName":"search","analyticsLabel":"searchHome","searchPayload":"term":"Healthy","searchHomeSection":"Top Categories"'], 'uuid': '90d3e6c8-18bd-11e7-93ae-92361f002671', 'type': 'STORE_CAROUSEL', 'stores': ['uuid': 'bc8a1d02-f0d8-4e30-97ef-6892733ab97f', 'trackingCode': '"uuid":"33882349-8bb1-426d-84df-9a25da08e606","codeType":"STORE","metaInfo":"pluginName":"recommendationFeedPlugin","analyticsLabel":"new_stores_by_city","storePayload":"storeUUID":"bc8a1d02-f0d8-4e30-97ef-6892733ab97f","isOrderable":true,"score":"total":0,"etdInfo":"dropoffETARange":"min":20,"max":30,"raw":25,"fareInfo":"multiplier":1', 'uuid': '4b001ddf-9952-4952-a0e3-a016d9f83059', 'trackingCode': '"uuid":"acb88709-2c57-427b-af94-97f0d227dac7","codeType":"STORE","metaInfo":"pluginName":"recommendationFeedPlugin","analyticsLabel":"new_stores_by_city","storePayload":"storeUUID":"4b001ddf-9952-4952-a0e3-a016d9f83059","isOrderable":true,"score":"total":0,"etdInfo":"dropoffETARange":"min":25,"max":35,"raw":30,"fareInfo":"multiplier":1', 'uuid': '3c9f5359-3c7e-4dde-9364-21f0a6910e34', 'trackingCode': '"uuid":"3047e213-eb07-4fa3-a7bc-918d015fd510","codeType":"STORE","metaInfo":"pluginName":"recommendationFeedPlugin","analyticsLabel":"new_stores_by_city","storePayload":"storeUUID":"3c9f5359-3c7e-4dde-9364-21f0a6910e34","isOrderable":true,"score":"total":0,"etdInfo":"dropoffETARange":"min":15,"max":25,"raw":20,"fareInfo":"multiplier":1'], 'title': 'New on Uber Eats', 'subtitle': '', 'carouselId': None, 'type': 'STORE', 'uuid': '231c5fe2-ce38-4126-99af-14ba416bba0e', 'type': 'STORE', 'uuid': 'cb68994f-632e-47c0-94bb-b649a208efcc', 'type': 'STORE', 'uuid': '827fb3f1-fa2a-4ad9-8af3-49c96ff06c65', 'type': 'STORE', 'uuid': 'ef8cfbdb-26c6-47c7-a1f2-d7b74a44cdd5', 'type': 'STORE', 'uuid': '51724c0c-107e-45cb-91a5-3deed50c911c', 'type': 'STORE', 'uuid': 'e51dd91a-74c3-46e8-9825-ed73451bbafe', 'type': 'STORE', 'uuid': 'f04e3597-898a-4c4d-b932-8984aa163d97', 'type': 'STORE', 'uuid': '9db7b92e-5691-44ad-84b6-3b11e09e3029', 'type': 'STORE', 'uuid': '099d3fcd-1de7-4c39-af82-8ba83030ae74', 'type': 'STORE', 'uuid': 'e2401047-e263-4583-8d95-1247c72186c2', 'type': 'STORE', 'uuid': 'c577c456-f8cb-4992-9073-e99113612538', 'type': 'STORE', 'uuid': 'ae69f5bc-9713-4f87-b8b9-a81b88dcc4ad', 'type': 'STORE', 'uuid': '43226175-49c4-4cdd-88b9-bf5d3238771b', 'type': 'STORE', 'uuid': '191a4ef2-7a62-4837-8b8a-0f7ab75808f3', 'type': 'STORE', 'uuid': 'bf329378-427b-4018-a2e5-93e0fe9deaba', 'type': 'STORE', 'uuid': 'c3cd766d-c462-46b7-bb69-c9b919bda05d', 'type': 'STORE', 'uuid': '4dc4368b-c8a5-44ac-9b92-b3cbedbf6750', 'type': 'STORE', 'uuid': 'e8b1edc6-2a53-45f6-85b2-1c7cde7478a1', 'type': 'STORE', 'uuid': 'e23c4303-474e-4024-9055-cc690300f9fb', 'type': 'STORE', 'uuid': 'b625de6a-c495-4595-a921-cdfb5d0a2c67', 'type': 'STORE', 'uuid': '57867065-3827-4f60-ad15-96cc9f1f0232', 'type': 'STORE', 'uuid': 'af87897d-1c59-4ee0-aba3-e72f08959c31', 'type': 'STORE', 'uuid': 'aefca145-6acf-4e39-87d9-3d98b794ce01', 'type': 'STORE', 'uuid': '43331a59-df5c-4896-848e-933da11984e5', 'type': 'STORE', 'uuid': '86a7c2b7-b268-4d22-a08f-7ffdb1e6e125', 'type': 'STORE', 'uuid': '4866d250-99b8-4051-a137-3382dcf16819', 'type': 'STORE', 'uuid': 'c55f2554-d23e-4932-877d-6d7520111cb4', 'type': 'STORE', 'uuid': 'ded9c2d0-4034-4e17-9cb9-4c5d0ab40b7a', 'type': 'STORE', 'uuid': 'dce9a67c-abb4-490b-9a24-6dbfe2e77562', 'type': 'STORE', 'uuid': 'b87e7a82-57ea-4717-b7dd-f76cd3dd4d5e', 'type': 'STORE', 'uuid': 'f970a4a0-51ec-4d1a-b4fc-8fda911d5c90', 'type': 'STORE', 'uuid': '6bb7f08f-b468-4b85-92b3-55a66a8b1ad8', 'type': 'STORE', 'uuid': '83dea20d-6f25-48e1-b4bc-283c0ab14034'], 'storesMap': '83dea20d-6f25-48e1-b4bc-283c0ab14034': 'heroImageUrl': 'https://d1ralsognjng37.cloudfront.net/b1ad418f-f17a-4032-9d66-25123de1e764.jpeg', 'citySlug': 'london', 'slug': 'mcdonalds-waterloo-station', 'title': "McDonald's® (Waterloo Station)", 'uuid': '83dea20d-6f25-48e1-b4bc-283c0ab14034', 'categories': ['£', 'Burgers', 'Breakfast and Brunch'], 'feedback': 'accessibilityText': 'Rated 4.1 out of 5 stars based on more than 500 reviews.', 'rating': 4.1, 'ratingCount': '500+', 'etaRange': 'text': '10–20 Min', 'textFormat': ['breakStyle': 'single', 'children': ['type': 'text', 'text': '10–20 Min', 'color': 'contentPrimary', 'fontStyle': 'regular', 'fontSize': 'body2']], 'fareBadge': None, 'promotion': None, 'isOpen': True, 'closedMessage': 'Currently unavailable', 'endorsement': None, 'promoTrackings': [], 'meta': 'deliveryFee': None, 'priceBucket': '£', 'categories': ['Burgers', 'Breakfast and Brunch'],

我想获取'title''categories'值,你们可以帮我吗?

答案

您必须遍历json结构:

import requests
import json

myProxy = 
            "http"  : "http://10.120.118.49:8080",
            "https"  : "https://10.120.118.49:8080"
            

data = "cacheKey": "JTdCJTIyYWRkcmVzcyUyMiUzQSUyMkxvbmRvbiUyMEV5ZSUyMiUyQyUyMnJlZmVyZW5jZSUyMiUzQSUyMkNoSUpjMm5TQUxrRWRrZ1JrdW9KSkJmemtVSSUyMiUyQyUyMnJlZmVyZW5jZVR5cGUlMjIlM0ElMjJnb29nbGVfcGxhY2VzJTIyJTJDJTIybGF0aXR1ZGUlMjIlM0E1MS41MDMxMDE1JTJDJTIybG9uZ2l0dWRlJTIyJTNBLTAuMTE3NDcyNzk5OTk5OTk5OTklN0Q=/DELIVERY///0/0//JTVCJTVE/",
        "feedSessionCount": "announcementCount": 0, "announcementLabel": "", "userQuery": "", "date": "", "startTime": 0, "endTime": 0, "carouselId": "", "sortAndFilters": []


headers = 
    "x-csrf-token": "x",
    'cookie': "uev2.id.xp=84c25cae-9049-4ed7-8119-b00e21bd099b; dId=f14e51e4-f3af-4da8-9cbd-f0f0024fa575; uev2.id.session=3c486ded-ffc4-4dfc-9a4e-849fa25afee4; uev2.ts.session=1583939016969; jwt-session=eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJpYXQiOjE1ODM5MzkwMTcsImV4cCI6MTU4NDAyNTQxN30.7-3tQOFimBd2up8wv94GsJacTnk4x1Cm498ZITSy71w; uev2.loc=%7B%22address%22%3A%7B%22address1%22%3A%22London%20Eye%22%2C%22address2%22%3A%22The%20Queen's%20Walk%2C%20South%20Bank%2C%20London%22%2C%22aptOrSuite%22%3A%22%22%2C%22city%22%3A%22%22%2C%22country%22%3A%22%22%2C%22eaterFormattedAddress%22%3A%22The%20Queen's%20Walk%2C%20South%20Bank%2C%20London%20SE1%207PB%2C%20UK%22%2C%22postalCode%22%3A%22%22%2C%22region%22%3A%22%22%2C%22subtitle%22%3A%22The%20Queen's%20Walk%2C%20South%20Bank%2C%20London%22%2C%22title%22%3A%22London%20Eye%22%2C%22uuid%22%3A%22%22%7D%2C%22latitude%22%3A51.503095699999996%2C%22longitude%22%3A-0.11750189999999999%2C%22reference%22%3A%22ChIJc2nSALkEdkgRkuoJJBfzkUI%22%2C%22referenceType%22%3A%22google_places%22%2C%22type%22%3A%22google_places%22%2C%22source%22%3A%22rev_geo_reference%22%7D; marketing_vistor_id=1cdd05e4-e3ea-40e3-a2d9-b8c790ba7b70; utag_main=v_id:0170ca1f682600a0ff2795e620200104e014200d00978$_sn:1$_se:6$_ss:0$_st:1583940871143$ses_id:1583939020843%3Bexp-session$_pn:3%3Bexp-session; _userUuid=; _gcl_au=1.1.1208413337.1583939021; QSI_HistorySession=https%3A%2F%2Fwww.ubereats.com%2Fen-US%2Ffeed%2F%3Fpl%3DJTdCJTIyYWRkcmVzcyUyMiUzQSUyMkxvbmRvbiUyMEV5ZSUyMiUyQyUyMnJlZmVyZW5jZSUyMiUzQSUyMkNoSUpjMm5TQUxrRWRrZ1JrdW9KSkJmemtVSSUyMiUyQyUyMnJlZmVyZW5jZVR5cGUlMjIlM0ElMjJnb29nbGVfcGxhY2VzJTIyJTJDJTIybGF0aXR1ZGUlMjIlM0E1MS41MDMxMDE1JTJDJTIybG9uZ2l0dWRlJTIyJTNBLTAuMTE3NDcyNzk5OTk5OTk5OTklN0Q%253D~1583939021598%7Chttps%3A%2F%2Fwww.ubereats.com%2Fen-US%2Ffeed%2F%3Fpl%3DJTdCJTIyYWRkcmVzcyUyMiUzQSUyMkxvbmRvbiUyMEV5ZSUyMiUyQyUyMnJlZmVyZW5jZSUyMiUzQSUyMkNoSUpjMm5TQUxrRWRrZ1JrdW9KSkJmemtVSSUyMiUyQyUyMnJlZmVyZW5jZVR5cGUlMjIlM0ElMjJnb29nbGVfcGxhY2VzJTIyJTJDJTIybGF0aXR1ZGUlMjIlM0E1MS41MDMxMDE1JTJDJTIybG9uZ2l0dWRlJTIyJTNBLTAuMTE3NDcyNzk5OTk5OTk5OTklN0Q%3D~1583939068750; _ga=GA1.2.455546941.1583939022; _gid=GA1.2.1252191334.1583939022; _fbp=fb.1.1583939022805.1654600085; _scid=0c232be0-9f0e-4e0e-a335-f92c9fa7f1f0; _sctr=1|1583877600000"


r = requests.post(
    "https://www.ubereats.com/api/getFeedV1?localeCode=en-US", json=data, headers=headers, proxies=myProxy).json()



data = r['data']['storesMap']
for k, v in data.items():
    title = v['title']
    categories = v['categories']
    print (title, categories)

以上是关于如何从json.loads()字典中获取值?的主要内容,如果未能解决你的问题,请参考以下文章

json.loads() 返回一个 unicode 对象而不是字典

Python 如何读取excel中的字典数据

python中json模块dumps和loads的区分

从注解返回的字典列表中获取name键的值,然后按名称排序?

json串 与字典的转换

如何将给定的数据放入字典?