Skip to content
Advertisement

Extracting JSON from HTML with BeautifulSoup

I’ve now tried everything for the past few hours but I can’t extract a specific thing from the HTML below. I want to grab the “sessionCartId” but I can’t figure out how….

Thats what i tried so far :

JavaScript

^^ This gives me the correct script tag but i cant transform it into a json nor get the sessioncarId

JavaScript

Advertisement

Answer

This is how you can extract that dictionary:

JavaScript

Result:

JavaScript

BeautifulSoup docs: https://beautiful-soup-4.readthedocs.io/en/latest/index.html

Advertisement