2017-09-04 8 views
0

re.searchを使用するのが難しいです。正規表現を使用しています。再検索する必要があります。ページテキスト/ javascript

ここでは、私がプルしたいテキスト/ javascriptの部分をjsonロードを介してjsonに変換します。

$(function() { 

    $product = $('#product-' + 12272257171); 

    new Shopify.OptionSelectors("product-select-12272257171", { product: {"id":12272257171,"title":"BODEGA X SAUCONY GRID 8000 \"CLASSIFIEDS\" - BLACK\/YELLOW\/WHITE","handle":"bodega-x-saucony-grid-8000-classifieds-black-yellow-white","description":"\u003cp\u003e\u003cspan\u003e\u003cstrong\u003ePLEASE BE MINDFUL -- \u003c\/strong\u003e\u003c\/span\u003e\u003c\/p\u003e\n\u003cp\u003e\u003cspan\u003e\u003cspan color=\"#ff0000\"\u003e\u003cb\u003e\u003c\/b\u003e\u003c\/span\u003e\u003cstrong\u003eALL SALES ARE FINAL ON THIS LIMITED RELEASE. NO EXCHANGES, RETURNS OR REFUNDS.\u003c\/strong\u003e\u003c\/span\u003e\u003c\/p\u003e","published_at":"2017-09-02T00:00:00-04:00","created_at":"2017-08-30T14:39:53-04:00","vendor":"SAUCONY","type":"FOOTWEAR","tags":["BODEGA","FOOTWEAR","NEW ARRIVALS","ONLINE","SAUCONY"],"price":13000,"price_min":13000,"price_max":13000,"available":true,"price_varies":false,"compare_at_price":null,"compare_at_price_min":0,"compare_at_price_max":0,"compare_at_price_varies":false,"variants":[{"id":50761752659,"title":"7","option1":"7","option2":null,"option3":null,"sku":"S70379-1-7","requires_shipping":true,"taxable":true,"featured_image":null,"available":true,"name":"BODEGA X SAUCONY GRID 8000 \"CLASSIFIEDS\" - BLACK\/YELLOW\/WHITE - 7","public_title":"7","options":["7"],"price":13000,"weight":1361,"compare_at_price":null,"inventory_quantity":1,"inventory_management":"shopify","inventory_policy":"deny","barcode":""},{"id":50761752723,"title":"7.5","option1":"7.5","option2":null,"option3":null,"sku":"S70379-1-7.5","requires_shipping":true,"taxable":true,"featured_image":null,"available":false,"name":"BODEGA X SAUCONY GRID 8000 \"CLASSIFIEDS\" - BLACK\/YELLOW\/WHITE - 7.5","public_title":"7.5","options":["7.5"],"price":13000,"weight":1361,"compare_at_price":null,"inventory_quantity":0,"inventory_management":"shopify","inventory_policy":"deny","barcode":""},{"id":50761752851,"title":"8","option1":"8","option2":null,"option3":null,"sku":"S70379-1-8","requires_shipping":true,"taxable":true,"featured_image":null,"available":false,"name":"BODEGA X SAUCONY GRID 8000 \"CLASSIFIEDS\" - BLACK\/YELLOW\/WHITE - 8","public_title":"8","options":["8"],"price":13000,"weight":1361,"compare_at_price":null,"inventory_quantity":0,"inventory_management":"shopify","inventory_policy":"deny","barcode":""},{"id":50761752915,"title":"8.5","option1":"8.5","option2":null,"option3":null,"sku":"S70379-1-8.5","requires_shipping":true,"taxable":true,"featured_image":null,"available":false,"name":"BODEGA X SAUCONY GRID 8000 \"CLASSIFIEDS\" - BLACK\/YELLOW\/WHITE - 8.5","public_title":"8.5","options":["8.5"],"price":13000,"weight":1361,"compare_at_price":null,"inventory_quantity":0,"inventory_management":"shopify","inventory_policy":"deny","barcode":""},{"id":50761752979,"title":"9","option1":"9","option2":null,"option3":null,"sku":"S70379-1-9","requires_shipping":true,"taxable":true,"featured_image":null,"available":true,"name":"BODEGA X SAUCONY GRID 8000 \"CLASSIFIEDS\" - BLACK\/YELLOW\/WHITE - 9","public_title":"9","options":["9"],"price":13000,"weight":1361,"compare_at_price":null,"inventory_quantity":1,"inventory_management":"shopify","inventory_policy":"deny","barcode":""},{"id":50761753107,"title":"9.5","option1":"9.5","option2":null,"option3":null,"sku":"S70379-1-9.5","requires_shipping":true,"taxable":true,"featured_image":null,"available":true,"name":"BODEGA X SAUCONY GRID 8000 \"CLASSIFIEDS\" - BLACK\/YELLOW\/WHITE - 9.5","public_title":"9.5","options":["9.5"],"price":13000,"weight":1361,"compare_at_price":null,"inventory_quantity":1,"inventory_management":"shopify","inventory_policy":"deny","barcode":""},{"id":50761753171,"title":"10","option1":"10","option2":null,"option3":null,"sku":"S70379-1-10","requires_shipping":true,"taxable":true,"featured_image":null,"available":true,"name":"BODEGA X SAUCONY GRID 8000 \"CLASSIFIEDS\" - BLACK\/YELLOW\/WHITE - 10","public_title":"10","options":["10"],"price":13000,"weight":1361,"compare_at_price":null,"inventory_quantity":1,"inventory_management":"shopify","inventory_policy":"deny","barcode":""},{"id":50761753299,"title":"10.5","option1":"10.5","option2":null,"option3":null,"sku":"S70379-1-10.5","requires_shipping":true,"taxable":true,"featured_image":null,"available":false,"name":"BODEGA X SAUCONY GRID 8000 \"CLASSIFIEDS\" - BLACK\/YELLOW\/WHITE - 10.5","public_title":"10.5","options":["10.5"],"price":13000,"weight":1361,"compare_at_price":null,"inventory_quantity":0,"inventory_management":"shopify","inventory_policy":"deny","barcode":""},{"id":50761753363,"title":"11","option1":"11","option2":null,"option3":null,"sku":"S70379-1-11","requires_shipping":true,"taxable":true,"featured_image":null,"available":true,"name":"BODEGA X SAUCONY GRID 8000 \"CLASSIFIEDS\" - BLACK\/YELLOW\/WHITE - 11","public_title":"11","options":["11"],"price":13000,"weight":1361,"compare_at_price":null,"inventory_quantity":1,"inventory_management":"shopify","inventory_policy":"deny","barcode":""},{"id":50761753427,"title":"11.5","option1":"11.5","option2":null,"option3":null,"sku":"S70379-1-11.5","requires_shipping":true,"taxable":true,"featured_image":null,"available":true,"name":"BODEGA X SAUCONY GRID 8000 \"CLASSIFIEDS\" - BLACK\/YELLOW\/WHITE - 11.5","public_title":"11.5","options":["11.5"],"price":13000,"weight":1361,"compare_at_price":null,"inventory_quantity":1,"inventory_management":"shopify","inventory_policy":"deny","barcode":""},{"id":50761753555,"title":"12","option1":"12","option2":null,"option3":null,"sku":"S70379-1-12","requires_shipping":true,"taxable":true,"featured_image":null,"available":false,"name":"BODEGA X SAUCONY GRID 8000 \"CLASSIFIEDS\" - BLACK\/YELLOW\/WHITE - 12","public_title":"12","options":["12"],"price":13000,"weight":1361,"compare_at_price":null,"inventory_quantity":0,"inventory_management":"shopify","inventory_policy":"deny","barcode":""},{"id":50761753619,"title":"13","option1":"13","option2":null,"option3":null,"sku":"S70379-1-13","requires_shipping":true,"taxable":true,"featured_image":null,"available":true,"name":"BODEGA X SAUCONY GRID 8000 \"CLASSIFIEDS\" - BLACK\/YELLOW\/WHITE - 13","public_title":"13","options":["13"],"price":13000,"weight":1361,"compare_at_price":null,"inventory_quantity":1,"inventory_management":"shopify","inventory_policy":"deny","barcode":""}],"images":["\/\/cdn.shopify.com\/s\/files\/1\/0208\/5268\/products\/Bodega_x_Saucony_Grid_8000_CL_S70379-1_side.jpg?v=1504298966","\/\/cdn.shopify.com\/s\/files\/1\/0208\/5268\/products\/Bodega_x_Saucony_Grid_8000_CL_S70379-1_angle.jpg?v=1504298966","\/\/cdn.shopify.com\/s\/files\/1\/0208\/5268\/products\/Bodega_x_Saucony_Grid_8000_CL_S70379-1-4.jpg?v=1504298966","\/\/cdn.shopify.com\/s\/files\/1\/0208\/5268\/products\/Bodega_x_Saucony_Grid_8000_CL_S70379-1-5.jpg?v=1504298966","\/\/cdn.shopify.com\/s\/files\/1\/0208\/5268\/products\/Bodega_x_Saucony_Grid_8000_CL_S70379-1-1.jpg?v=1504298966","\/\/cdn.shopify.com\/s\/files\/1\/0208\/5268\/products\/Bodega_x_Saucony_Grid_8000_CL_S70379-1-9.jpg?v=1504298966"],"featured_image":"\/\/cdn.shopify.com\/s\/files\/1\/0208\/5268\/products\/Bodega_x_Saucony_Grid_8000_CL_S70379-1_side.jpg?v=1504298966","options":["Size"],"content":"\u003cp\u003e\u003cspan\u003e\u003cstrong\u003ePLEASE BE MINDFUL -- \u003c\/strong\u003e\u003c\/span\u003e\u003c\/p\u003e\n\u003cp\u003e\u003cspan\u003e\u003cspan color=\"#ff0000\"\u003e\u003cb\u003e\u003c\/b\u003e\u003c\/span\u003e\u003cstrong\u003eALL SALES ARE FINAL ON THIS LIMITED RELEASE. NO EXCHANGES, RETURNS OR REFUNDS.\u003c\/strong\u003e\u003c\/span\u003e\u003c\/p\u003e"}, onVariantSelected: selectCallback, enableHistoryState: true }); 

    jQuery('#product-12272257171 .single-option-selector:eq(0)').val("7").trigger('change'); 

    jQuery('.swatch :radio').change(function() { 
     var optionIndex = jQuery(this).parents('.swatch').attr('data-option-index'); 
     var optionValue = jQuery(this).val(); 
     jQuery('#product-12272257171 .single-option-selector').eq(optionIndex).find('option').filter(function() { return jQuery(this).text() == optionValue }).parent().val(optionValue).trigger('change'); 
    }); 
    }); 

heresコードへのリンク。私はちょうどこれをjsonに変換したいので、内側のものをいくつか選択し、IDが最も多くのインベントリを持つものを解析することができます。ここ

はページのURLです:私が作った正規表現のhttps://packershoes.com/products/bodega-x-saucony-grid-8000-classifieds-black-yellow-white

HERESに少ししかし

json_str = re.search('{"id".+inventory.+}', reqs.text).group(0) 
      json_str = json_str.encode('ascii', 'ignore') 
      product_json = json.loads(json_str) 
      prdt_json = product_json['variants'] 

答えて

0

はそれを考え出したエラーを取得しておく........... .re.search( 'new Shopify.OptionSelectors(。+ product:({。+})、onVariantSelected。+)'、reqs.text).group(1)

関連する問題