One option would be to use selenium. In particular, you can use execute_script to convert to a JSON string which Python can easily parse.
Since I don't know what the URL of the page you are working with is, I just created a local HTML file which included your script tag example. Using headless is not mandatory and I only added that option so the browser window doesn't open.
test.html
<!DOCTYPE html>
<html>
<body>
<script>
var main_obj = {
"link": "",
"stock": "",
"price": [{"qty": 1000, "value": "100$"}, {"qty": 10000, "value": "1000$"}]
}
</script>
</body>
</html>
Script
In[2]: import os
...: import json
...:
...: from selenium import webdriver
...:
...: chrome_options = webdriver.ChromeOptions()
...: chrome_options.add_argument('--headless')
...: driver = webdriver.Chrome(chrome_options=chrome_options)
...:
...: driver.get('file://{}/test.html'.format(os.getcwd()))
...: json_string = driver.execute_script('return JSON.stringify(main_obj)')
...: driver.quit()
...:
...: json_data = json.loads(json_string)
In[3]: json_data
Out[3]:
{'link': '',
'stock': '',
'price': [{'qty': 1000, 'value': '100$'}, {'qty': 10000, 'value': '1000$'}]}
In[4]: for item in json_data['price']:
...: print('Quantity: {:d}\tValue: ${:.2f}'.format(
...: item['qty'], float(item['value'].rstrip('$'))
...: ))
...:
Quantity: 1000 Value: $100.00
Quantity: 10000 Value: $1000.00
import jsonand usejson.loads(json_string)...developer.rhino3d.com/guides/rhinopython/python-xml-json