I need some help extracting javascript data to my python programme.
soup = BeautifulSoup(wm, "html.parser")
scripts = soup.findAll('script')
s = scripts[:50]
print(s)
Using the above i am getting the below output - again within a javascript
I am looking to extract the data below from this - any help would be much appreciated!
In essence i am looking to get the items.push> saved as a python dictionary.
var items = [];
items.push({
'item_id': '196388',
'item_name': 'Rolex Submariner 116610 LN',
'item_brand': 'Rolex',
'item_collection': 'Submariner',
'item_variant': '116610 LN',
'item_category': 'watch',
'price': '12500',
'currency': 'GBP',
'quantity': '1',
'item_material_case': 'Steel',
'item_material_strap': 'Steel (Oyster)',
'item_dial': 'Black',
'item_size': '40',
'item_box': 'True',
'item_papers': 'True',
'item_special_edition': 'False',
'item_available': 'instock',
'item_sellable': 'sellable',
'item_year': '2013'
});
items.push({
'item_id': '211954',
'item_name': 'Rolex Submariner 116610 LN',
'item_brand': 'Rolex',
'item_collection': 'Submariner',
'item_variant': '116610 LN',
'item_category': 'watch',
'price': '12400',
'currency': 'GBP',
'quantity': '1',
'item_material_case': 'Steel',
'item_material_strap': 'Steel (Oyster)',
'item_dial': 'Black',
'item_size': '40',
'item_box': 'True',
'item_papers': 'True',
'item_special_edition': 'False',
'item_available': 'preorder',
'item_sellable': 'sellable',
'item_year': '2012'
});
Seeing your data I think you fetch them from an API, so given the endpoint you can get the dict using this:
import requests
response = requests.get(endpoint)
json = response.json() // your dict