이러한 json 파일을 찝을려면 정규식이나 크롤링으로 어떻게 찝어야 할까요??
본문
<script type="application/json" data-product-json="">
{"id":6684371943518,"title":"MALBON x WDS SHORT SLEEVE TEE","handle":"malbon-x-wds-short-sleeve-tee-beige","description":"\u003cmeta charset=\"utf-8\"\u003e\n\u003cul data-mce-fragment=\"1\"\u003e\n\u003cli data-mce-fragment=\"1\"\u003eUnisex T-shirt\u003c\/li\u003e\n\u003cli data-mce-fragment=\"1\"\u003eBuckets Logo Printed on Left Chest\u003c\/li\u003e\n\u003cli data-mce-fragment=\"1\"\u003eMalbon Golf and Wind Logo on Back\u003c\/li\u003e\n\u003cli data-mce-fragment=\"1\"\u003eCo Branded Neck Label\u003c\/li\u003e\n\u003c\/ul\u003e","published_at":"2022-06-10T11:00:02-07:00","created_at":"2022-05-23T15:31:42-07:00","vendor":"WIND AND SEA","type":"SHIRTS","tags":["6.9.22 wds 2","products\/malbon-x-wds-short-sleeve-tee-beige","products\/malbon-x-wds-short-sleeve-tee-black","products\/malbon-x-wds-short-sleeve-tee-green","products\/malbon-x-wds-short-sleeve-tee-white"],"price":8000,"price_min":8000,"price_max":8000,"available":false,"price_varies":false,"compare_at_price":null,"compare_at_price_min":0,"compare_at_price_max":0,"compare_at_price_varies":false,"variants":[{"id":39706234191966,"title":"S \/ BEIGE","option1":"S","option2":"BEIGE","option3":null,"sku":"WDS-MALBON-10-BGE-S","requires_shipping":true,"taxable":true,"featured_image":null,"available":false,"name":"MALBON x WDS SHORT SLEEVE TEE - S \/ BEIGE","public_title":"S \/ BEIGE","options":["S","BEIGE"],"price":8000,"weight":0,"compare_at_price":null,"inventory_quantity":0,"inventory_management":"shopify","inventory_policy":"deny","barcode":null,"requires_selling_plan":false,"selling_plan_allocations":[]},{"id":39706234224734,"title":"M \/ BEIGE","option1":"M","option2":"BEIGE","option3":null,"sku":"WDS-MALBON-10-BGE-M","requires_shipping":true,"taxable":true,"featured_image":null,"available":false,"name":"MALBON x WDS SHORT SLEEVE TEE - M \/ BEIGE","public_title":"M \/ BEIGE","options":["M","BEIGE"],"price":8000,"weight":0,"compare_at_price":null,"inventory_quantity":0,"inventory_management":"shopify","inventory_policy":"deny","barcode":null,"requires_selling_plan":false,"selling_plan_allocations":[]},{"id":39706234257502,"title":"L \/ BEIGE","option1":"L","option2":"BEIGE","option3":null,"sku":"WDS-MALBON-10-BGE-L","requires_shipping":true,"taxable":true,"featured_image":null,"available":false,"name":"MALBON x WDS SHORT SLEEVE TEE - L \/ BEIGE","public_title":"L \/ BEIGE","options":["L","BEIGE"],"price":8000,"weight":0,"compare_at_price":null,"inventory_quantity":0,"inventory_management":"shopify","inventory_policy":"deny","barcode":null,"requires_selling_plan":false,"selling_plan_allocations":[]},{"id":39706234290270,"title":"XL \/ BEIGE","option1":"XL","option2":"BEIGE","option3":null,"sku":"WDS-MALBON-10-BGE-XL","requires_shipping":true,"taxable":true,"featured_image":null,"available":false,"name":"MALBON x WDS SHORT SLEEVE TEE - XL \/ BEIGE","public_title":"XL \/ BEIGE","options":["XL","BEIGE"],"price":8000,"weight":0,"compare_at_price":null,"inventory_quantity":0,"inventory_management":"shopify","inventory_policy":"deny","barcode":null,"requires_selling_plan":false,"selling_plan_allocations":[]}],"images":["\/\/cdn.shopify.com\/s\/files\/1\/1770\/9541\/products\/WDS-MALBON-10_BEIGE_1.jpg?v=1654713484","\/\/cdn.shopify.com\/s\/files\/1\/1770\/9541\/products\/WDS-MALBON-10_BEIGE_2.jpg?v=1654713483","\/\/cdn.shopify.com\/s\/files\/1\/1770\/9541\/products\/WDS-MALBON-10_BEIGE_3.jpg?v=1654713484","\/\/cdn.shopify.com\/s\/files\/1\/1770\/9541\/products\/WDS-MALBON-10_BEIGE_4.jpg?v=1654713484","\/\/cdn.shopify.com\/s\/files\/1\/1770\/9541\/products\/WDS-MALBON-10_BEIGE_5.jpg?v=1654713484"],"featured_image":"\/\/cdn.shopify.com\/s\/files\/1\/1770\/9541\/products\/WDS-MALBON-10_BEIGE_1.jpg?v=1654713484","options":["Size","Color"],"media":[{"alt":null,"id":21297586995294,"position":1,"preview_image":{"aspect_ratio":1.0,"height":1200,"width":1200,"src":"https:\/\/cdn.shopify.com\/s\/files\/1\/1770\/9541\/products\/WDS-MALBON-10_BEIGE_1.jpg?v=1654713484"},"aspect_ratio":1.0,"height":1200,"media_type":"image","src":"https:\/\/cdn.shopify.com\/s\/files\/1\/1770\/9541\/products\/WDS-MALBON-10_BEIGE_1.jpg?v=1654713484","width":1200},{"alt":null,"id":21297587028062,"position":2,"preview_image":{"aspect_ratio":1.0,"height":1200,"width":1200,"src":"https:\/\/cdn.shopify.com\/s\/files\/1\/1770\/9541\/products\/WDS-MALBON-10_BEIGE_2.jpg?v=1654713483"},"aspect_ratio":1.0,"height":1200,"media_type":"image","src":"https:\/\/cdn.shopify.com\/s\/files\/1\/1770\/9541\/products\/WDS-MALBON-10_BEIGE_2.jpg?v=1654713483","width":1200},{"alt":null,"id":21297587060830,"position":3,"preview_image":{"aspect_ratio":1.0,"height":1200,"width":1200,"src":"https:\/\/cdn.shopify.com\/s\/files\/1\/1770\/9541\/products\/WDS-MALBON-10_BEIGE_3.jpg?v=1654713484"},"aspect_ratio":1.0,"height":1200,"media_type":"image","src":"https:\/\/cdn.shopify.com\/s\/files\/1\/1770\/9541\/products\/WDS-MALBON-10_BEIGE_3.jpg?v=1654713484","width":1200},{"alt":null,"id":21297587093598,"position":4,"preview_image":{"aspect_ratio":1.0,"height":1200,"width":1200,"src":"https:\/\/cdn.shopify.com\/s\/files\/1\/1770\/9541\/products\/WDS-MALBON-10_BEIGE_4.jpg?v=1654713484"},"aspect_ratio":1.0,"height":1200,"media_type":"image","src":"https:\/\/cdn.shopify.com\/s\/files\/1\/1770\/9541\/products\/WDS-MALBON-10_BEIGE_4.jpg?v=1654713484","width":1200},{"alt":null,"id":21297587126366,"position":5,"preview_image":{"aspect_ratio":1.0,"height":1200,"width":1200,"src":"https:\/\/cdn.shopify.com\/s\/files\/1\/1770\/9541\/products\/WDS-MALBON-10_BEIGE_5.jpg?v=1654713484"},"aspect_ratio":1.0,"height":1200,"media_type":"image","src":"https:\/\/cdn.shopify.com\/s\/files\/1\/1770\/9541\/products\/WDS-MALBON-10_BEIGE_5.jpg?v=1654713484","width":1200}],"requires_selling_plan":false,"selling_plan_groups":[],"content":"\u003cmeta charset=\"utf-8\"\u003e\n\u003cul data-mce-fragment=\"1\"\u003e\n\u003cli data-mce-fragment=\"1\"\u003eUnisex T-shirt\u003c\/li\u003e\n\u003cli data-mce-fragment=\"1\"\u003eBuckets Logo Printed on Left Chest\u003c\/li\u003e\n\u003cli data-mce-fragment=\"1\"\u003eMalbon Golf and Wind Logo on Back\u003c\/li\u003e\n\u003cli data-mce-fragment=\"1\"\u003eCo Branded Neck Label\u003c\/li\u003e\n\u003c\/ul\u003e"}
</script>
이러한 json 파일을 찝을려면 정규식이나 크롤링으로 어떻게 찝어야 할까요??
답변 2
$json = '<script type="application/json" data-product-json="">
{"id":6684371943518,"title":"MALBON x WDS SHORT SLEEVE TEE","handle":"malbon-x-wds-short-sleeve-tee-beige","description":"\u003cmeta charset=\"utf-8\"\u003e\n\u003cul data-mce-fragment=\"1\"\u003e\n\u003cli data-mce-fragment=\"1\"\u003eUnisex T-shirt\u003c\/li\u003e\n\u003cli data-mce-fragment=\"1\"\u003eBuckets Logo Printed on Left Chest\u003c\/li\u003e\n\u003cli data-mce-fragment=\"1\"\u003eMalbon Golf and Wind Logo on Back\u003c\/li\u003e\n\u003cli data-mce-fragment=\"1\"\u003eCo Branded Neck Label\u003c\/li\u003e\n\u003c\/ul\u003e","published_at":"2022-06-10T11:00:02-07:00","created_at":"2022-05-23T15:31:42-07:00","vendor":"WIND AND SEA","type":"SHIRTS","tags":["6.9.22 wds 2","products\/malbon-x-wds-short-sleeve-tee-beige","products\/malbon-x-wds-short-sleeve-tee-black","products\/malbon-x-wds-short-sleeve-tee-green","products\/malbon-x-wds-short-sleeve-tee-white"],"price":8000,"price_min":8000,"price_max":8000,"available":false,"price_varies":false,"compare_at_price":null,"compare_at_price_min":0,"compare_at_price_max":0,"compare_at_price_varies":false,"variants":[{"id":39706234191966,"title":"S \/ BEIGE","option1":"S","option2":"BEIGE","option3":null,"sku":"WDS-MALBON-10-BGE-S","requires_shipping":true,"taxable":true,"featured_image":null,"available":false,"name":"MALBON x WDS SHORT SLEEVE TEE - S \/ BEIGE","public_title":"S \/ BEIGE","options":["S","BEIGE"],"price":8000,"weight":0,"compare_at_price":null,"inventory_quantity":0,"inventory_management":"shopify","inventory_policy":"deny","barcode":null,"requires_selling_plan":false,"selling_plan_allocations":[]},{"id":39706234224734,"title":"M \/ BEIGE","option1":"M","option2":"BEIGE","option3":null,"sku":"WDS-MALBON-10-BGE-M","requires_shipping":true,"taxable":true,"featured_image":null,"available":false,"name":"MALBON x WDS SHORT SLEEVE TEE - M \/ BEIGE","public_title":"M \/ BEIGE","options":["M","BEIGE"],"price":8000,"weight":0,"compare_at_price":null,"inventory_quantity":0,"inventory_management":"shopify","inventory_policy":"deny","barcode":null,"requires_selling_plan":false,"selling_plan_allocations":[]},{"id":39706234257502,"title":"L \/ BEIGE","option1":"L","option2":"BEIGE","option3":null,"sku":"WDS-MALBON-10-BGE-L","requires_shipping":true,"taxable":true,"featured_image":null,"available":false,"name":"MALBON x WDS SHORT SLEEVE TEE - L \/ BEIGE","public_title":"L \/ BEIGE","options":["L","BEIGE"],"price":8000,"weight":0,"compare_at_price":null,"inventory_quantity":0,"inventory_management":"shopify","inventory_policy":"deny","barcode":null,"requires_selling_plan":false,"selling_plan_allocations":[]},{"id":39706234290270,"title":"XL \/ BEIGE","option1":"XL","option2":"BEIGE","option3":null,"sku":"WDS-MALBON-10-BGE-XL","requires_shipping":true,"taxable":true,"featured_image":null,"available":false,"name":"MALBON x WDS SHORT SLEEVE TEE - XL \/ BEIGE","public_title":"XL \/ BEIGE","options":["XL","BEIGE"],"price":8000,"weight":0,"compare_at_price":null,"inventory_quantity":0,"inventory_management":"shopify","inventory_policy":"deny","barcode":null,"requires_selling_plan":false,"selling_plan_allocations":[]}],"images":["\/\/cdn.shopify.com\/s\/files\/1\/1770\/9541\/products\/WDS-MALBON-10_BEIGE_1.jpg?v=1654713484","\/\/cdn.shopify.com\/s\/files\/1\/1770\/9541\/products\/WDS-MALBON-10_BEIGE_2.jpg?v=1654713483","\/\/cdn.shopify.com\/s\/files\/1\/1770\/9541\/products\/WDS-MALBON-10_BEIGE_3.jpg?v=1654713484","\/\/cdn.shopify.com\/s\/files\/1\/1770\/9541\/products\/WDS-MALBON-10_BEIGE_4.jpg?v=1654713484","\/\/cdn.shopify.com\/s\/files\/1\/1770\/9541\/products\/WDS-MALBON-10_BEIGE_5.jpg?v=1654713484"],"featured_image":"\/\/cdn.shopify.com\/s\/files\/1\/1770\/9541\/products\/WDS-MALBON-10_BEIGE_1.jpg?v=1654713484","options":["Size","Color"],"media":[{"alt":null,"id":21297586995294,"position":1,"preview_image":{"aspect_ratio":1.0,"height":1200,"width":1200,"src":"https:\/\/cdn.shopify.com\/s\/files\/1\/1770\/9541\/products\/WDS-MALBON-10_BEIGE_1.jpg?v=1654713484"},"aspect_ratio":1.0,"height":1200,"media_type":"image","src":"https:\/\/cdn.shopify.com\/s\/files\/1\/1770\/9541\/products\/WDS-MALBON-10_BEIGE_1.jpg?v=1654713484","width":1200},{"alt":null,"id":21297587028062,"position":2,"preview_image":{"aspect_ratio":1.0,"height":1200,"width":1200,"src":"https:\/\/cdn.shopify.com\/s\/files\/1\/1770\/9541\/products\/WDS-MALBON-10_BEIGE_2.jpg?v=1654713483"},"aspect_ratio":1.0,"height":1200,"media_type":"image","src":"https:\/\/cdn.shopify.com\/s\/files\/1\/1770\/9541\/products\/WDS-MALBON-10_BEIGE_2.jpg?v=1654713483","width":1200},{"alt":null,"id":21297587060830,"position":3,"preview_image":{"aspect_ratio":1.0,"height":1200,"width":1200,"src":"https:\/\/cdn.shopify.com\/s\/files\/1\/1770\/9541\/products\/WDS-MALBON-10_BEIGE_3.jpg?v=1654713484"},"aspect_ratio":1.0,"height":1200,"media_type":"image","src":"https:\/\/cdn.shopify.com\/s\/files\/1\/1770\/9541\/products\/WDS-MALBON-10_BEIGE_3.jpg?v=1654713484","width":1200},{"alt":null,"id":21297587093598,"position":4,"preview_image":{"aspect_ratio":1.0,"height":1200,"width":1200,"src":"https:\/\/cdn.shopify.com\/s\/files\/1\/1770\/9541\/products\/WDS-MALBON-10_BEIGE_4.jpg?v=1654713484"},"aspect_ratio":1.0,"height":1200,"media_type":"image","src":"https:\/\/cdn.shopify.com\/s\/files\/1\/1770\/9541\/products\/WDS-MALBON-10_BEIGE_4.jpg?v=1654713484","width":1200},{"alt":null,"id":21297587126366,"position":5,"preview_image":{"aspect_ratio":1.0,"height":1200,"width":1200,"src":"https:\/\/cdn.shopify.com\/s\/files\/1\/1770\/9541\/products\/WDS-MALBON-10_BEIGE_5.jpg?v=1654713484"},"aspect_ratio":1.0,"height":1200,"media_type":"image","src":"https:\/\/cdn.shopify.com\/s\/files\/1\/1770\/9541\/products\/WDS-MALBON-10_BEIGE_5.jpg?v=1654713484","width":1200}],"requires_selling_plan":false,"selling_plan_groups":[],"content":"\u003cmeta charset=\"utf-8\"\u003e\n\u003cul data-mce-fragment=\"1\"\u003e\n\u003cli data-mce-fragment=\"1\"\u003eUnisex T-shirt\u003c\/li\u003e\n\u003cli data-mce-fragment=\"1\"\u003eBuckets Logo Printed on Left Chest\u003c\/li\u003e\n\u003cli data-mce-fragment=\"1\"\u003eMalbon Golf and Wind Logo on Back\u003c\/li\u003e\n\u003cli data-mce-fragment=\"1\"\u003eCo Branded Neck Label\u003c\/li\u003e\n\u003c\/ul\u003e"}
</script>';
$json = json_decode(strip_tags($json),true);
print_r($json);
이러면 php 배열로 json 이 변환됩니다.
!-->$json_dom = $dom -> find("script[data-product-json]",0);
$json_data = json_decode(strip_tags($json_dom),true);
//echo "<xmp>".$json_data."</xmp>";
echo $json_data['id'];
json 불러와지네요 너무 감사합니다.