如何在json文本中指定关键字?

时间:2017-08-30 03:13:42

标签: python regex

我有很多产品列表,我试图找出一种方法来使用关键字来提取我正在寻找的产品。对于此示例,我想找到T恤名称Kiss Tee。然后我使用正则表达式来获取此代码的ID -

ids = re.findall(('id": ([^"]+)"'), html1)

现在它会提取所有ID,我需要指定什么才能使用上面的关键字来提取Kiss Tee ID?

html1 =

'''
    "T-Shirts": [{
            "name": "Kiss Tee",
            "id": 170783,
            "image_url": "//d17ol771963kd3.cloudfront.net/137402/ca/CvFnLzjSIZU.jpg",
            "image_url_hi": "//d17ol771963kd3.cloudfront.net/137402/rc/CvFnLzjSIZU.jpg",
            "price": 4000,
            "sale_price": 0,
            "new_item": false,
            "position": 25,
            "category_name": "T-Shirts"
        },

'''

full url response.text -

"{\"unique_image_url_prefixes\":[],\"products_and_categories\":{\"Accessories\":[{\"name\":\"Supreme\u00ae/Hanes\u00ae Tagless Tees (3 Pack)\",\"id\":170791,\"image_url\":\"//d17ol771963kd3.cloudfront.net/137585/ca/mOCTZ5CVF1A.jpg\",\"image_url_hi\":\"//d17ol771963kd3.cloudfront.net/137585/rc/mOCTZ5CVF1A.jpg\",\"price\":2800,\"sale_price\":0,\"new_item\":false,\"position\":35,\"category_name\":\"Accessories\"},{\"name\":\"Supreme\u00ae/Hanes\u00ae Boxer Briefs (4 Pack)\",\"id\":170793,\"image_url\":\"//d17ol771963kd3.cloudfront.net/137591/ca/EZINLXsgih4.jpg\",\"image_url_hi\":\"//d17ol771963kd3.cloudfront.net/137591/rc/EZINLXsgih4.jpg\",\"price\":3600,\"sale_price\":0,\"new_item\":false,\"position\":36,\"category_name\":\"Accessories\"},{\"name\":\"Supreme\u00ae/Hanes\u00ae Crew Socks (4 Pack)\",\"id\":170792,\"image_url\":\"//d17ol771963kd3.cloudfront.net/137587/ca/z6zqv9yB4mw.jpg\",\"image_url_hi\":\"//d17ol771963kd3.cloudfront.net/137587/rc/z6zqv9yB4mw.jpg\",\"price\":2000,\"sale_price\":0,\"new_item\":false,\"position\":37,\"category_name\":\"Accessories\"},{\"name\":\"100 Dollar Bill Gold Pendant\",\"id\":170715,\"image_url\":\"//d17ol771963kd3.cloudfront.net/136795/ca/N8k_Ttm9htk.jpg\",\"image_url_hi\":\"//d17ol771963kd3.cloudfront.net/136795/rc/N8k_Ttm9htk.jpg\",\"price\":32800,\"sale_price\":0,\"new_item\":false,\"position\":66,\"category_name\":\"Accessories\"},{\"name\":\"Supreme\u00ae/SOG\u00ae Collapsible Shovel\",\"id\":170716,\"image_url\":\"//d17ol771963kd3.cloudfront.net/137810/ca/A-tpH2vU2uo.jpg\",\"image_url_hi\":\"//d17ol771963kd3.cloudfront.net/137810/rc/A-tpH2vU2uo.jpg\",\"price\":3800,\"sale_price\":0,\"new_item\":false,\"position\":67,\"category_name\":\"Accessories\"},{\"name\":\"Supreme\u00ae/Rifkin Safety Sac\u00ae\",\"id\":170714,\"image_url\":\"//d17ol771963kd3.cloudfront.net/136790/ca/QgBmS_MHQwE.jpg\",\"image_url_hi\":\"//d17ol771963kd3.cloudfront.net/136790/rc/QgBmS_MHQwE.jpg\",\"price\":5800,\"sale_price\":0,\"new_item\":false,\"position\":68,\"category_name\":\"Accessories\"},{\"name\":\"Faux Snakeskin Belt\",\"id\":170719,\"image_url\":\"//d17ol771963kd3.cloudfront.net/139895/ca/vE6t97xr_Qg.jpg\",\"image_url_hi\":\"//d17ol771963kd3.cloudfront.net/139895/rc/vE6t97xr_Qg.jpg\",\"price\":12800,\"sale_price\":0,\"new_item\":false,\"position\":69,\"category_name\":\"Accessories\"},{\"name\":\"Gold Trim Ceramic Ashtray\",\"id\":170718,\"image_url\":\"//d17ol771963kd3.cloudfront.net/136816/ca/XuW_IKrdkb8.jpg\",\"image_url_hi\":\"//d17ol771963kd3.cloudfront.net/136816/rc/XuW_IKrdkb8.jpg\",\"price\":3400,\"sale_price\":0,\"new_item\":false,\"position\":70,\"category_name\":\"Accessories\"},{\"name\":\"Diamond Cut Zippo\u00ae\",\"id\":170717,\"image_url\":\"//d17ol771963kd3.cloudfront.net/136809/ca/0X_Tno2TckI.jpg\",\"image_url_hi\":\"//d17ol771963kd3.cloudfront.net/136809/rc/0X_Tno2TckI.jpg\",\"price\":6000,\"sale_price\":0,\"new_item\":false,\"position\":71,\"category_name\":\"Accessories\"},{\"name\":\"Supreme\u00ae/NITECORE\u00ae Mini Magnetic Flashlight\",\"id\":170720,\"image_url\":\"//d17ol771963kd3.cloudfront.net/136830/ca/-Mp7A9MSv24.jpg\",\"image_url_hi\":\"//d17ol771963kd3.cloudfront.net/136830/rc/-Mp7A9MSv24.jpg\",\"price\":4800,\"sale_price\":0,\"new_item\":false,\"position\":72,\"category_name\":\"Accessories\"},{\"name\":\"Pledge Allegiance Keychain\",\"id\":170722,\"image_url\":\"//d17ol771963kd3.cloudfront.net/136839/ca/qLL2O2zaqTI.jpg\",\"image_url_hi\":\"//d17ol771963kd3.cloudfront.net/136839/rc/qLL2O2zaqTI.jpg\",\"price\":1800,\"sale_price\":0,\"new_item\":false,\"position\":73,\"category_name\":\"Accessories\"},{\"name\":\"Handcuffs Keychain\",\"id\":170723,\"image_url\":\"//d17ol771963kd3.cloudfront.net/136842/ca/EY0KFPO02T4.jpg\",\"image_url_hi\":\"//d17ol771963kd3.cloudfront.net/136842/rc/EY0KFPO02T4.jpg\",\"price\":1800,\"sale_price\":0,\"new_item\":false,\"position\":74,\"category_name\":\"Accessories\"},{\"name\":\"Gonz Ramm Pin\",\"id\":170721,\"image_url\":\"//d17ol771963kd3.cloudfront.net/136835/ca/cMQmSm485UE.jpg\",\"image_url_hi\":\"//d17ol771963kd3.cloudfront.net/136835/rc/cMQmSm485UE.jpg\",\"price\":800,\"sale_price\":0,\"new_item\":false,\"position\":75,\"category_name\":\"Accessories\"}],\"Bags\":[{\"name\":\"Backpack\",\"id\":170724,\"image_url\":\"//d17ol771963kd3.cloudfront.net/137595/ca/k_5cUAhSc34.jpg\",\"image_url_hi\":\"//d17ol771963kd3.cloudfront.net/137595/rc/k_5cUAhSc34.jpg\",\"price\":14800,\"sale_price\":0,\"new_item\":false,\"position\":62,\"category_name\":\"Bags\"},{\"name\":\"Duffle Bag\",\"id\":170725,\"image_url\":\"//d17ol771963kd3.cloudfront.net/137539/ca/ZLDGm7pJrnc.jpg\",\"image_url_hi\":\"//d17ol771963kd3.cloudfront.net/137539/rc/ZLDGm7pJrnc.jpg\",\"price\":14800,\"sale_price\":0,\"new_item\":false,\"position\":63,\"category_name\":\"Bags\"},{\"name\":\"Waist Bag\",\"id\":170726,\"image_url\":\"//d17ol771963kd3.cloudfront.net/139802/ca/XbfaJKdZYjQ.jpg\",\"image_url_hi\":\"//d17ol771963kd3.cloudfront.net/139802/rc/XbfaJKdZYjQ.jpg\",\"price\":8800,\"sale_price\":0,\"new_item\":false,\"position\":64,\"category_name\":\"Bags\"},{\"name\":\"Shoulder Bag\",\"id\":170727,\"image_url\":\"//d17ol771963kd3.cloudfront.net/136901/ca/zOWxGiO3PBo.jpg\",\"image_url_hi\":\"//d17ol771963kd3.cloudfront.net/136901/rc/zOWxGiO3PBo.jpg\",\"price\":4800,\"sale_price\":0,\"new_item\":false,\"position\":65,\"category_name\":\"Bags\"}],\"Hats\":[{\"name\":\"Heart New Era\u00ae\",\"id\":170732,\"image_url\":\"//d17ol771963kd3.cloudfront.net/136947/ca/1ea-OAlE5jE.jpg\",\"image_url_hi\":\"//d17ol771963kd3.cloudfront.net/136947/rc/1ea-OAlE5jE.jpg\",\"price\":4800,\"sale_price\":0,\"new_item\":false,\"position\":51,\"category_name\":\"Hats\"},{\"name\":\"Overdyed Ripstop Camp Cap\",\"id\":170733,\"image_url\":\"//d17ol771963kd3.cloudfront.net/136953/ca/KpsgT-XhoOc.jpg\",\"image_url_hi\":\"//d17ol771963kd3.cloudfront.net/136953/rc/KpsgT-XhoOc.jpg\",\"price\":4800,\"sale_price\":0,\"new_item\":false,\"position\":52,\"category_name\":\"Hats\"},{\"name\":\"NYCO Twill Camp Cap\",\"id\":170738,\"image_url\":\"//d17ol771963kd3.cloudfront.net/138266/ca/O3EXC6Y-moU.jpg\",\"image_url_hi\":\"//d17ol771963kd3.cloudfront.net/138266/rc/O3EXC6Y-moU.jpg\",\"price\":4800,\"sale_price\":0,\"new_item\":false,\"position\":53,\"category_name\":\"Hats\"},{\"name\":\"Tonal S Logo 6-Panel\",\"id\":170735,\"image_url\":\"//d17ol771963kd3.cloudfront.net/137649/ca/S9qvyrcJN80.jpg\",\"image_url_hi\":\"//d17ol771963kd3.cloudfront.net/137649/rc/S9qvyrcJN80.jpg\",\"price\":4800,\"sale_price\":0,\"new_item\":false,\"position\":54,\"category_name\":\"Hats\"},{\"name\":\"Gonz Ramm 6-Panel\",\"id\":170737,\"image_url\":\"//d17ol771963kd3.cloudfront.net/136990/ca/BMhhyouAxY0.jpg\",\"image_url_hi\":\"//d17ol771963kd3.cloudfront.net/136990/rc/BMhhyouAxY0.jpg\",\"price\":4400,\"sale_price\":0,\"new_item\":false,\"position\":55,\"category_name\":\"Hats\"},{\"name\":\"Brushed Twill Script 6-Panel\",\"id\":170734,\"image_url\":\"//d17ol771963kd3.cloudfront.net/136965/ca/hC-APu3IQus.jpg\",\"image_url_hi\":\"//d17ol771963kd3.cloudfront.net/136965/rc/hC-APu3IQus.jpg\",\"price\":4800,\"sale_price\":0,\"new_item\":false,\"position\":56,\"category_name\":\"Hats\"},{\"name\":\"Fire 5-Panel\",\"id\":170731,\"image_url\":\"//d17ol771963kd3.cloudfront.net/136935/ca/jf0PPeoX0Co.jpg\",\"image_url_hi\":\"//d17ol771963kd3.cloudfront.net/136935/rc/jf0PPeoX0Co.jpg\",\"price\":4400,\"sale_price\":0,\"new_item\":false,\"position\":57,\"category_name\":\"Hats\"},{\"name\":\"Survival Nylon 6-Panel\",\"id\":170736,\"image_url\":\"//d17ol771963kd3.cloudfront.net/136983/ca/U-gn4AZ6VDM.jpg\",\"image_url_hi\":\"//d17ol771963kd3.cloudfront.net/136983/rc/U-gn4AZ6VDM.jpg\",\"price\":4400,\"sale_price\":0,\"new_item\":false,\"position\":58,\"category_name\":\"Hats\"},{\"name\":\"New Era\u00ae Snake Script Beanie\",\"id\":170728,\"image_url\":\"//d17ol771963kd3.cloudfront.net/136904/ca/0ojFttzWzsY.jpg\",\"image_url_hi\":\"//d17ol771963kd3.cloudfront.net/136904/rc/0ojFttzWzsY.jpg\",\"price\":3800,\"sale_price\":0,\"new_item\":false,\"position\":59,\"category_name\":\"Hats\"},{\"name\":\"Centerpiece Beanie\",\"id\":170730,\"image_url\":\"//d17ol771963kd3.cloudfront.net/138200/ca/VpyOhQmwko8.jpg\",\"image_url_hi\":\"//d17ol771963kd3.cloudfront.net/138200/rc/VpyOhQmwko8.jpg\",\"price\":3200,\"sale_price\":0,\"new_item\":false,\"position\":60,\"category_name\":\"Hats\"},{\"name\":\"Loose Gauge Beanie\",\"id\":170729,\"image_url\":\"//d17ol771963kd3.cloudfront.net/138142/ca/EflUwejZZsA.jpg\",\"image_url_hi\":\"//d17ol771963kd3.cloudfront.net/138142/rc/EflUwejZZsA.jpg\",\"price\":3200,\"sale_price\":0,\"new_item\":false,\"position\":61,\"category_name\":\"Hats\"}],\"Jackets\":[{\"name\":\"Supreme\u00ae/Schott\u00ae Chief Tassel Perfecto\",\"id\":170745,\"image_url\":\"//d17ol771963kd3.cloudfront.net/137089/ca/gwtWehM9UA4.jpg\",\"image_url_hi\":\"//d17ol771963kd3.cloudfront.net/137089/rc/gwtWehM9UA4.jpg\",\"price\":79800,\"sale_price\":0,\"new_item\":false,\"position\":0,\"category_name\":\"Jackets\"},{\"name\":\"Wool Overcoat\",\"id\":170739,\"image_url\":\"//d17ol771963kd3.cloudfront.net/137002/ca/7Tp9rXlmGHc.jpg\",\"image_url_hi\":\"//d17ol771963kd3.cloudfront.net/137002/rc/7Tp9rXlmGHc.jpg\",\"price\":56800,\"sale_price\":0,\"new_item\":false,\"position\":1,\"category_name\":\"Jackets\"},{\"name\":\"Gonz Ramm Varsity Jacket\",\"id\":170742,\"image_url\":\"//d17ol771963kd3.cloudfront.net/137059/ca/ZKRqkSv-U-0.jpg\",\"image_url_hi\":\"//d17ol771963kd3.cloudfront.net/137059/rc/ZKRqkSv-U-0.jpg\",\"price\":39800,\"sale_price\":0,\"new_item\":false,\"position\":2,\"category_name\":\"Jackets\"},{\"name\":\"Scarface\u2122 The World Is Yours Denim Jacket\",\"id\":170743,\"image_url\":\"//d17ol771963kd3.cloudfront.net/139440/ca/-K5LMlTy-eU.jpg\",\"image_url_hi\":\"//d17ol771963kd3.cloudfront.net/139440/rc/-K5LMlTy-eU.jpg\",\"price\":32800,\"sale_price\":0,\"new_item\":false,\"position\":3,\"category_name\":\"Jackets\"},{\"name\":\"Taped Seam Jacket\",\"id\":170740,\"image_url\":\"//d17ol771963kd3.cloudfront.net/137557/ca/GGwmwLlJtzE.jpg\",\"image_url_hi\":\"//d17ol771963kd3.cloudfront.net/137557/rc/GGwmwLlJtzE.jpg\",\"price\":29800,\"sale_price\":0,\"new_item\":false,\"position\":4,\"category_name\":\"Jackets\"},{\"name\":\"Quilted Liner Hooded Jacket\",\"id\":170741,\"image_url\":\"//d17ol771963kd3.cloudfront.net/137055/ca/Zmfrp21VXlo.jpg\",\"image_url_hi\":\"//d17ol771963kd3.cloudfront.net/137055/rc/Zmfrp21VXlo.jpg\",\"price\":17800,\"sale_price\":0,\"new_item\":false,\"position\":5,\"category_name\":\"Jackets\"},{\"name\":\"Arc Track Jacket\",\"id\":170744,\"image_url\":\"//d17ol771963kd3.cloudfront.net/137079/ca/EJZyf9_1p3E.jpg\",\"image_url_hi\":\"//d17ol771963kd3.cloudfront.net/137079/rc/EJZyf9_1p3E.jpg\",\"price\":15800,\"sale_price\":0,\"new_item\":false,\"position\":6,\"category_name\":\"Jackets\"}],\"Tops/Sweaters\":[{\"name\":\"Leather Front Polo Sweater\",\"id\":170771,\"image_url\":\"//d17ol771963kd3.cloudfront.net/139088/ca/QmS28ZowiJs.jpg\",\"image_url_hi\":\"//d17ol771963kd3.cloudfront.net/139088/rc/QmS28ZowiJs.jpg\",\"price\":39800,\"sale_price\":0,\"new_item\":false,\"position\":11,\"category_name\":\"Tops/Sweaters\"},{\"name\":\"Repeat Sweater\",\"id\":170770,\"image_url\":\"//d17ol771963kd3.cloudfront.net/137275/ca/1XZOd7ynIfA.jpg\",\"image_url_hi\":\"//d17ol771963kd3.cloudfront.net/137275/rc/1XZOd7ynIfA.jpg\",\"price\":14800,\"sale_price\":0,\"new_item\":false,\"position\":12,\"category_name\":\"Tops/Sweaters\"},{\"name\":\"Snake Script Logo Baseball Jersey\",\"id\":170752,\"image_url\":\"//d17ol771963kd3.cloudfront.net/138816/ca/vN8HSHPo8ZY.jpg\",\"image_url_hi\":\"//d17ol771963kd3.cloudfront.net/138816/rc/vN8HSHPo8ZY.jpg\",\"price\":12800,\"sale_price\":0,\"new_item\":false,\"position\":18,\"category_name\":\"Tops/Sweaters\"},{\"name\":\"Paisley L/S Polo\",\"id\":170749,\"image_url\":\"//d17ol771963kd3.cloudfront.net/137117/ca/BH9ADYtYGbw.jpg\",\"image_url_hi\":\"//d17ol771963kd3.cloudfront.net/137117/rc/BH9ADYtYGbw.jpg\",\"price\":11000,\"sale_price\":0,\"new_item\":false,\"position\":19,\"category_name\":\"Tops/Sweaters\"},{\"name\":\"Gonz Ramm Polo\",\"id\":170747,\"image_url\":\"//d17ol771963kd3.cloudfront.net/137106/ca/YpKQFkXs5zY.jpg\",\"image_url_hi\":\"//d17ol771963kd3.cloudfront.net/137106/rc/YpKQFkXs5zY.jpg\",\"price\":8800,\"sale_price\":0,\"new_item\":false,\"position\":20,\"category_name\":\"Tops/Sweaters\"},{\"name\":\"Logo Stripe L/S Top\",\"id\":170746,\"image_url\":\"//d17ol771963kd3.cloudfront.net/137096/ca/CtdCbQsiZUw.jpg\",\"image_url_hi\":\"//d17ol771963kd3.cloudfront.net/137096/rc/CtdCbQsiZUw.jpg\",\"price\":8800,\"sale_price\":0,\"new_item\":false,\"position\":21,\"category_name\":\"Tops/Sweaters\"},{\"name\":\"Michelangelo L/S Top\",\"id\":170748,\"image_url\":\"//d17ol771963kd3.cloudfront.net/137110/ca/ncCNHNvYqZQ.jpg\",\"image_url_hi\":\"//d17ol771963kd3.cloudfront.net/137110/rc/ncCNHNvYqZQ.jpg\",\"price\":11000,\"sale_price\":0,\"new_item\":false,\"position\":22,\"category_name\":\"Tops/Sweaters\"},{\"name\":\"Dotted Arc Top\",\"id\":170751,\"image_url\":\"//d17ol771963kd3.cloudfront.net/137148/ca/_IyGdyazdDA.jpg\",\"image_url_hi\":\"//d17ol771963kd3.cloudfront.net/137148/rc/_IyGdyazdDA.jpg\",\"price\":7800,\"sale_price\":0,\"new_item\":false,\"position\":23,\"category_name\":\"Tops/Sweaters\"},{\"name\":\"S/S Pocket Tee\",\"id\":170750,\"image_url\":\"//d17ol771963kd3.cloudfront.net/138534/ca/nBYReN9N6vE.jpg\",\"image_url_hi\":\"//d17ol771963kd3.cloudfront.net/138534/rc/nBYReN9N6vE.jpg\",\"price\":6200,\"sale_price\":0,\"new_item\":false,\"position\":24,\"category_name\":\"Tops/Sweaters\"}],\"Pants\":[{\"name\":\"Scarface\u2122 The World Is Yours 5-Pocket Jeans\",\"id\":170762,\"image_url\":\"//d17ol771963kd3.cloudfront.net/137234/ca/xnIUjgLJPys.jpg\",\"image_url_hi\":\"//d17ol771963kd3.cloudfront.net/137234/rc/xnIUjgLJPys.jpg\",\"price\":18800,\"sale_price\":0,\"new_item\":false,\"position\":38,\"category_name\":\"Pants\"},{\"name\":\"Denim Overalls\",\"id\":170754,\"image_url\":\"//d17ol771963kd3.cloudfront.net/138820/ca/aixxxUSZtdE.jpg\",\"image_url_hi\":\"//d17ol771963kd3.cloudfront.net/138820/rc/aixxxUSZtdE.jpg\",\"price\":16800,\"sale_price\":0,\"new_item\":false,\"position\":39,\"category_name\":\"Pants\"},{\"name\":\"Washed Regular Jeans\",\"id\":170755,\"image_url\":\"//d17ol771963kd3.cloudfront.net/138844/ca/vIwX2C2QBZg.jpg\",\"image_url_hi\":\"//d17ol771963kd3.cloudfront.net/138844/rc/vIwX2C2QBZg.jpg\",\"price\":13800,\"sale_price\":0,\"new_item\":false,\"position\":40,\"category_name\":\"Pants\"},{\"name\":\"Work Pant\",\"id\":170753,\"image_url\":\"//d17ol771963kd3.cloudfront.net/138684/ca/uJzpssXp030.jpg\",\"image_url_hi\":\"//d17ol771963kd3.cloudfront.net/138684/rc/uJzpssXp030.jpg\",\"price\":11800,\"sale_price\":0,\"new_item\":false,\"position\":41,\"category_name\":\"Pants\"},{\"name\":\"Rigid Slim Jeans\",\"id\":170758,\"image_url\":\"//d17ol771963kd3.cloudfront.net/138882/ca/9cC1lvijENQ.jpg\",\"image_url_hi\":\"//d17ol771963kd3.cloudfront.net/138882/rc/9cC1lvijENQ.jpg\",\"price\":14800,\"sale_price\":0,\"new_item\":false,\"position\":42,\"category_name\":\"Pants\"},{\"name\":\"Stone Washed Black Slim Jeans\",\"id\":170756,\"image_url\":\"//d17ol771963kd3.cloudfront.net/137195/ca/QlL-10HOyOI.jpg\",\"image_url_hi\":\"//d17ol771963kd3.cloudfront.net/137195/rc/QlL-10HOyOI.jpg\",\"price\":13600,\"sale_price\":0,\"new_item\":false,\"position\":43,\"category_name\":\"Pants\"},{\"name\":\"Stone Washed Slim Jeans\",\"id\":170757,\"image_url\":\"//d17ol771963kd3.cloudfront.net/138877/ca/i9tLZQ6I7Y8.jpg\",\"image_url_hi\":\"//d17ol771963kd3.cloudfront.net/138877/rc/i9tLZQ6I7Y8.jpg\",\"price\":15800,\"sale_price\":0,\"new_item\":false,\"position\":44,\"category_name\":\"Pants\"},{\"name\":\"Realtree\u00ae Camo Flannel Pant\",\"id\":170760,\"image_url\":\"//d17ol771963kd3.cloudfront.net/137211/ca/SzklJOrrnTo.jpg\",\"image_url_hi\":\"//d17ol771963kd3.cloudfront.net/137211/rc/SzklJOrrnTo.jpg\",\"price\":11800,\"sale_price\":0,\"new_item\":false,\"position\":45,\"category_name\":\"Pants\"},{\"name\":\"Tonal S Logo Sweatpant\",\"id\":170778,\"image_url\":\"//d17ol771963kd3.cloudfront.net/139477/ca/5hdZoL4n_AQ.jpg\",\"image_url_hi\":\"//d17ol771963kd3.cloudfront.net/139477/rc/5hdZoL4n_AQ.jpg\",\"price\":13800,\"sale_price\":0,\"new_item\":false,\"position\":46,\"category_name\":\"Pants\"},{\"name\":\"Patchwork Sweatpant\",\"id\":170776,\"image_url\":\"//d17ol771963kd3.cloudfront.net/137319/ca/fxefz_HQ8Fc.jpg\",\"image_url_hi\":\"//d17ol771963kd3.cloudfront.net/137319/rc/fxefz_HQ8Fc.jpg\",\"price\":16800,\"sale_price\":0,\"new_item\":false,\"position\":47,\"category_name\":\"Pants\"},{\"name\":\"Taped Seam Pant\",\"id\":170761,\"image_url\":\"//d17ol771963kd3.cloudfront.net/139799/ca/nohB6-VhR4s.jpg\",\"image_url_hi\":\"//d17ol771963kd3.cloudfront.net/139799/rc/nohB6-VhR4s.jpg\",\"price\":19800,\"sale_price\":0,\"new_item\":false,\"position\":48,\"category_name\":\"Pants\"},{\"name\":\"Arc Track Pant\",\"id\":170759,\"image_url\":\"//d17ol771963kd3.cloudfront.net/137204/ca/N6yMQCndpfU.jpg\",\"image_url_hi\":\"//d17ol771963kd3.cloudfront.net/137204/rc/N6yMQCndpfU.jpg\",\"price\":12800,\"sale_price\":0,\"new_item\":false,\"position\":49,\"category_name\":\"Pants\"}],\"Shirts\":[{\"name\":\"Plaid Flannel Zip Up Shirt\",\"id\":170766,\"image_url\":\"//d17ol771963kd3.cloudfront.net/137258/ca/tk03VOKN-C4.jpg\",\"image_url_hi\":\"//d17ol771963kd3.cloudfront.net/137258/rc/tk03VOKN-C4.jpg\",\"price\":12800,\"sale_price\":0,\"new_item\":false,\"position\":7,\"category_name\":\"Shirts\"},{\"name\":\"Realtree\u00ae Camo Flannel Shirt\",\"id\":170763,\"image_url\":\"//d17ol771963kd3.cloudfront.net/137238/ca/YaRSt3ikuUs.jpg\",\"image_url_hi\":\"//d17ol771963kd3.cloudfront.net/137238/rc/YaRSt3ikuUs.jpg\",\"price\":11800,\"sale_price\":0,\"new_item\":false,\"position\":8,\"category_name\":\"Shirts\"},{\"name\":\"Gonz Ramm Work Shirt\",\"id\":170765,\"image_url\":\"//d17ol771963kd3.cloudfront.net/138919/ca/Yk5J5riu3rQ.jpg\",\"image_url_hi\":\"//d17ol771963kd3.cloudfront.net/138919/rc/Yk5J5riu3rQ.jpg\",\"price\":12800,\"sale_price\":0,\"new_item\":false,\"position\":9,\"category_name\":\"Shirts\"},{\"name\":\"Oxford Shirt\",\"id\":170764,\"image_url\":\"//d17ol771963kd3.cloudfront.net/138875/ca/7Vva0ro5GN4.jpg\",\"image_url_hi\":\"//d17ol771963kd3.cloudfront.net/138875/rc/7Vva0ro5GN4.jpg\",\"price\":11800,\"sale_price\":0,\"new_item\":false,\"position\":10,\"category_name\":\"Shirts\"}],\"Skate\":[{\"name\":\"Supreme\u00ae/Independent\u00ae Truck\",\"id\":170789,\"image_url\":\"//d17ol771963kd3.cloudfront.net/137574/ca/IrAbl7l9IVo.jpg\",\"image_url_hi\":\"//d17ol771963kd3.cloudfront.net/137574/rc/IrAbl7l9IVo.jpg\",\"price\":5000,\"sale_price\":0,\"new_item\":false,\"position\":76,\"category_name\":\"Skate\"},{\"name\":\"Supreme\u00ae/Spitfire\u00ae Classic Wheels\",\"id\":170790,\"image_url\":\"//d17ol771963kd3.cloudfront.net/137577/ca/Qxvd-81GOF8.jpg\",\"image_url_hi\":\"//d17ol771963kd3.cloudfront.net/137577/rc/Qxvd-81GOF8.jpg\",\"price\":3000,\"sale_price\":0,\"new_item\":false,\"position\":77,\"category_name\":\"Skate\"},{\"name\":\"Blood and Semen Skateboard\",\"id\":170767,\"image_url\":\"//d17ol771963kd3.cloudfront.net/139796/ca/NJlmtyCgY_w.jpg\",\"image_url_hi\":\"//d17ol771963kd3.cloudfront.net/139796/rc/NJlmtyCgY_w.jpg\",\"price\":6000,\"sale_price\":0,\"new_item\":false,\"position\":78,\"category_name\":\"Skate\"},{\"name\":\"Gonz Ramm Skateboard\",\"id\":170768,\"image_url\":\"//d17ol771963kd3.cloudfront.net/137262/ca/M3ViYKrX7p8.jpg\",\"image_url_hi\":\"//d17ol771963kd3.cloudfront.net/137262/rc/M3ViYKrX7p8.jpg\",\"price\":4900,\"sale_price\":0,\"new_item\":false,\"position\":79,\"category_name\":\"Skate\"}],\"Shorts\":[{\"name\":\"Gonz Heads Short\",\"id\":170769,\"image_url\":\"//d17ol771963kd3.cloudfront.net/137267/ca/UEoRoBf9LbA.jpg\",\"image_url_hi\":\"//d17ol771963kd3.cloudfront.net/137267/rc/UEoRoBf9LbA.jpg\",\"price\":12800,\"sale_price\":0,\"new_item\":false,\"position\":50,\"category_name\":\"Shorts\"}],\"Sweatshirts\":[{\"name\":\"Patchwork Hooded Sweatshirt\",\"id\":170775,\"image_url\":\"//d17ol771963kd3.cloudfront.net/137316/ca/GKxaZD2iNCU.jpg\",\"image_url_hi\":\"//d17ol771963kd3.cloudfront.net/137316/rc/GKxaZD2iNCU.jpg\",\"price\":18800,\"sale_price\":0,\"new_item\":false,\"position\":13,\"category_name\":\"Sweatshirts\"},{\"name\":\"Centerpiece Hooded Sweatshirt\",\"id\":170777,\"image_url\":\"//d17ol771963kd3.cloudfront.net/139408/ca/5MgBaqvwDs8.jpg\",\"image_url_hi\":\"//d17ol771963kd3.cloudfront.net/139408/rc/5MgBaqvwDs8.jpg\",\"price\":15800,\"sale_price\":0,\"new_item\":false,\"position\":14,\"category_name\":\"Sweatshirts\"},{\"name\":\"Blocked Hooded Sweatshirt\",\"id\":170774,\"image_url\":\"//d17ol771963kd3.cloudfront.net/137310/ca/jY5jqY6JLe8.jpg\",\"image_url_hi\":\"//d17ol771963kd3.cloudfront.net/137310/rc/jY5jqY6JLe8.jpg\",\"price\":15800,\"sale_price\":0,\"new_item\":false,\"position\":15,\"category_name\":\"Sweatshirts\"},{\"name\":\"Tonal S Logo Hooded Sweatshirt\",\"id\":170772,\"image_url\":\"//d17ol771963kd3.cloudfront.net/137292/ca/BnhN_ftLEbM.jpg\",\"image_url_hi\":\"//d17ol771963kd3.cloudfront.net/137292/rc/BnhN_ftLEbM.jpg\",\"price\":15800,\"sale_price\":0,\"new_item\":false,\"position\":16,\"category_name\":\"Sweatshirts\"},{\"name\":\"Team Crewneck\",\"id\":170773,\"image_url\":\"//d17ol771963kd3.cloudfront.net/139141/ca/lq1UHN6nq8s.jpg\",\"image_url_hi\":\"//d17ol771963kd3.cloudfront.net/139141/rc/lq1UHN6nq8s.jpg\",\"price\":14800,\"sale_price\":0,\"new_item\":false,\"position\":17,\"category_name\":\"Sweatshirts\"}],\"T-Shirts\":[{\"name\":\"Kiss Tee\",\"id\":170783,\"image_url\":\"//d17ol771963kd3.cloudfront.net/137402/ca/CvFnLzjSIZU.jpg\",\"image_url_hi\":\"//d17ol771963kd3.cloudfront.net/137402/rc/CvFnLzjSIZU.jpg\",\"price\":4000,\"sale_price\":0,\"new_item\":false,\"position\":25,\"category_name\":\"T-Shirts\"},{\"name\":\"Fuck With Your Head Tee\",\"id\":170781,\"image_url\":\"//d17ol771963kd3.cloudfront.net/137377/ca/a4lDAQC5K5Q.jpg\",\"image_url_hi\":\"//d17ol771963kd3.cloudfront.net/137377/rc/a4lDAQC5K5Q.jpg\",\"price\":3400,\"sale_price\":0,\"new_item\":false,\"position\":26,\"category_name\":\"T-Shirts\"},{\"name\":\"DNA Tee\",\"id\":170782,\"image_url\":\"//d17ol771963kd3.cloudfront.net/137391/ca/LySrN_OOK74.jpg\",\"image_url_hi\":\"//d17ol771963kd3.cloudfront.net/137391/rc/LySrN_OOK74.jpg\",\"price\":3400,\"sale_price\":0,\"new_item\":false,\"position\":27,\"category_name\":\"T-Shirts\"},{\"name\":\"Venus Tee\",\"id\":170779,\"image_url\":\"//d17ol771963kd3.cloudfront.net/138333/ca/JnkXMcbzemg.jpg\",\"image_url_hi\":\"//d17ol771963kd3.cloudfront.net/138333/rc/JnkXMcbzemg.jpg\",\"price\":3400,\"sale_price\":0,\"new_item\":false,\"position\":28,\"category_name\":\"T-Shirts\"},{\"name\":\"Nas Tee\",\"id\":170780,\"image_url\":\"//d17ol771963kd3.cloudfront.net/137366/ca/Am0dyTgmEJg.jpg\",\"image_url_hi\":\"//d17ol771963kd3.cloudfront.net/137366/rc/Am0dyTgmEJg.jpg\",\"price\":4400,\"sale_price\":0,\"new_item\":false,\"position\":29,\"category_name\":\"T-Shirts\"},{\"name\":\"Gonz Heads Tee\",\"id\":170785,\"image_url\":\"//d17ol771963kd3.cloudfront.net/137424/ca/MdHAxBoGom8.jpg\",\"image_url_hi\":\"//d17ol771963kd3.cloudfront.net/137424/rc/MdHAxBoGom8.jpg\",\"price\":4400,\"sale_price\":0,\"new_item\":false,\"position\":30,\"category_name\":\"T-Shirts\"},{\"name\":\"Dollar Tee\",\"id\":170787,\"image_url\":\"//d17ol771963kd3.cloudfront.net/137460/ca/DEaAk78urxg.jpg\",\"image_url_hi\":\"//d17ol771963kd3.cloudfront.net/137460/rc/DEaAk78urxg.jpg\",\"price\":3400,\"sale_price\":0,\"new_item\":false,\"position\":31,\"category_name\":\"T-Shirts\"},{\"name\":\"Fuck Love Tee\",\"id\":170788,\"image_url\":\"//d17ol771963kd3.cloudfront.net/137470/ca/COkmYVdksMU.jpg\",\"image_url_hi\":\"//d17ol771963kd3.cloudfront.net/137470/rc/COkmYVdksMU.jpg\",\"price\":3400,\"sale_price\":0,\"new_item\":false,\"position\":32,\"category_name\":\"T-Shirts\"},{\"name\":\"Crash Tee\",\"id\":170786,\"image_url\":\"//d17ol771963kd3.cloudfront.net/139863/ca/Foz-Tyfp5Js.jpg\",\"image_url_hi\":\"//d17ol771963kd3.cloudfront.net/139863/rc/Foz-Tyfp5Js.jpg\",\"price\":3400,\"sale_price\":0,\"new_item\":false,\"position\":33,\"category_name\":\"T-Shirts\"},{\"name\":\"Bloom L/S Tee\",\"id\":170784,\"image_url\":\"//d17ol771963kd3.cloudfront.net/137409/ca/riwpeGex0wo.jpg\",\"image_url_hi\":\"//d17ol771963kd3.cloudfront.net/137409/rc/riwpeGex0wo.jpg\",\"price\":4400,\"sale_price\":0,\"new_item\":false,\"position\":34,\"category_name\":\"T-Shirts\"}]},\"last_mobile_api_update\":\"2015-02-06T14:47:32.034-05:00\",\"release_date\":\"08/24/2017\",\"release_week\":\"1FW17\"}"

衬衫款全部 -

 ,\"T-Shirts\":[{\"name\":\"Kiss Tee\",\"id\":170783,\"image_url\":\"//d17ol771963kd3.cloudfront.net/137402/ca/CvFnLzjSIZU.jpg\",\"image_url_hi\":\"//d17ol771963kd3.cloudfront.net/137402/rc/CvFnLzjSIZU.jpg\",\"price\":4000,\"sale_price\":0,\"new_item\":false,\"position\":25,\"category_name\":\"T-Shirts\"},{\"name\":\"Fuck With Your Head Tee\",\"id\":170781,\"image_url\":\"//d17ol771963kd3.cloudfront.net/137377/ca/a4lDAQC5K5Q.jpg\",\"image_url_hi\":\"//d17ol771963kd3.cloudfront.net/137377/rc/a4lDAQC5K5Q.jpg\",\"price\":3400,\"sale_price\":0,\"new_item\":false,\"position\":26,\"category_name\":\"T-Shirts\"},{\"name\":\"DNA Tee\",\"id\":170782,\"image_url\":\"//d17ol771963kd3.cloudfront.net/137391/ca/LySrN_OOK74.jpg\",\"image_url_hi\":\"//d17ol771963kd3.cloudfront.net/137391/rc/LySrN_OOK74.jpg\",\"price\":3400,\"sale_price\":0,\"new_item\":false,\"position\":27,\"category_name\":\"T-Shirts\"},{\"name\":\"Venus Tee\",\"id\":170779,\"image_url\":\"//d17ol771963kd3.cloudfront.net/138333/ca/JnkXMcbzemg.jpg\",\"image_url_hi\":\"//d17ol771963kd3.cloudfront.net/138333/rc/JnkXMcbzemg.jpg\",\"price\":3400,\"sale_price\":0,\"new_item\":false,\"position\":28,\"category_name\":\"T-Shirts\"},{\"name\":\"Nas Tee\",\"id\":170780,\"image_url\":\"//d17ol771963kd3.cloudfront.net/137366/ca/Am0dyTgmEJg.jpg\",\"image_url_hi\":\"//d17ol771963kd3.cloudfront.net/137366/rc/Am0dyTgmEJg.jpg\",\"price\":4400,\"sale_price\":0,\"new_item\":false,\"position\":29,\"category_name\":\"T-Shirts\"},{\"name\":\"Gonz Heads Tee\",\"id\":170785,\"image_url\":\"//d17ol771963kd3.cloudfront.net/137424/ca/MdHAxBoGom8.jpg\",\"image_url_hi\":\"//d17ol771963kd3.cloudfront.net/137424/rc/MdHAxBoGom8.jpg\",\"price\":4400,\"sale_price\":0,\"new_item\":false,\"position\":30,\"category_name\":\"T-Shirts\"},{\"name\":\"Dollar Tee\",\"id\":170787,\"image_url\":\"//d17ol771963kd3.cloudfront.net/137460/ca/DEaAk78urxg.jpg\",\"image_url_hi\":\"//d17ol771963kd3.cloudfront.net/137460/rc/DEaAk78urxg.jpg\",\"price\":3400,\"sale_price\":0,\"new_item\":false,\"position\":31,\"category_name\":\"T-Shirts\"},{\"name\":\"Fuck Love Tee\",\"id\":170788,\"image_url\":\"//d17ol771963kd3.cloudfront.net/137470/ca/COkmYVdksMU.jpg\",\"image_url_hi\":\"//d17ol771963kd3.cloudfront.net/137470/rc/COkmYVdksMU.jpg\",\"price\":3400,\"sale_price\":0,\"new_item\":false,\"position\":32,\"category_name\":\"T-Shirts\"},{\"name\":\"Crash Tee\",\"id\":170786,\"image_url\":\"//d17ol771963kd3.cloudfront.net/139863/ca/Foz-Tyfp5Js.jpg\",\"image_url_hi\":\"//d17ol771963kd3.cloudfront.net/139863/rc/Foz-Tyfp5Js.jpg\",\"price\":3400,\"sale_price\":0,\"new_item\":false,\"position\":33,\"category_name\":\"T-Shirts\"},{\"name\":\"Bloom L/S Tee\",\"id\":170784,\"image_url\":\"//d17ol771963kd3.cloudfront.net/137409/ca/riwpeGex0wo.jpg\",\"image_url_hi\":\"//d17ol771963kd3.cloudfront.net/137409/rc/riwpeGex0wo.jpg\",\"price\":4400,\"sale_price\":0,\"new_item\":false,\"position\":34,\"category_name\":\"T-Shirts\"}]},\"last_mobile_api_update\":\"2015-02-06T14:47:32.034-05:00\",\"release_date\":\"08/24/2017\",\"release_week\":\"1FW17\"}"

2 个答案:

答案 0 :(得分:1)

查看json模块。您可以json.loads您的数据并进行迭代。

import json

tshirt_data = '''[{
    "name": "Kiss Tee",
    "id": 170783,
    "image_url": "//d17ol771963kd3.cloudfront.net/137402/ca/CvFnLzjSIZU.jpg",
    "image_url_hi": "//d17ol771963kd3.cloudfront.net/137402/rc/CvFnLzjSIZU.jpg",
    "price": 4000,
    "sale_price": 0,
    "new_item": false,
    "position": 25,
    "category_name": "T-Shirts"
}]'''

for entry in json.loads(tshirt_data):
    if entry['name'] == 'Kiss Tee':
        print(entry['id'])

以上将输出正确的ID:170783

答案 1 :(得分:0)

import json

myData = json.loads(JSON_TEXT)
for tshirts in myData['T-Shirts']:
  if tshirts['name'] == 'Kiss Tee':
    print(tshirts[id])