Having trouble extracting data from the script tag. Specifically, I need to extract the data within the jsonSwatchConfig [ ], focusing on attributes 'option_id' and 'us'.
var jar = require('request').jar();
var request = require('request').defaults({ jar: jar });
var cheerio = require("cheerio");
var cloudscraper = require('cloudscraper');
var fs = require('fs');
const logT = require('log-timestamp');
var open = require('open');
var today = new Date();
var randomsize;
var webdriver = require('selenium-webdriver');
var sizes =[];
function product() {
// code here
}
This is the output I am currently getting:
{ "jsonSwatchConfig":
[{"option_id":"18","us":"7","eu":"40","uk":"6","cm":"25"},
// more data
] } },
"*" : { "Magento_Swatches/js/catalog-add-to-cart": {} } }
I have tried splitting and removing but unable to achieve desired results.
The source of the HTML script tag is as follows:
<script type="text/x-magento-init">
{
"[data-role=swatch-options]": {
// code here
},
"Svd_Catalog/js/svd.swatch.renderer": {
"jsonSwatchConfig": [{"option_id":"24","us":"4","eu":"36","uk":"3","cm":"23"},{"option_id":"22","us":"5","eu":"37.5","uk":"4.5","cm":"23.5"},
// more data
}]
},
"*" : {
"Magento_Swatches/js/catalog-add-to-cart": {}
}
}</script>
Looking for a secure and efficient way to extract the data. Any suggestions would be appreciated.