J
J
juventino962021-06-23 18:38:59
Python
juventino96, 2021-06-23 18:38:59

Get JSON variable from BeautifulSoup Python?

How to get json variable (window.detailData) from this pretty text


window.__version__map = {
'magicEditLoaderVersion': '0.0.75',
'icbuPcDetailAll': '0.0.9'
}
window.detailData = {"globalData":{"asddsa":true}, "renderType":"js_ssr"} }}

Answer the question

In order to leave comments, you need to log in

1 answer(s)
S
soremix, 2021-06-23
@juventino96

It's just in the page code, right? Better get it regularly.

import re
html = '''window.__version__map = {
'magicEditLoaderVersion': '0.0.75',
'icbuPcDetailAll': '0.0.9'
}
window.detailData = {"globalData":{"asddsa":true}, "renderType":"js_ssr"}}}'''
data = re.search(r'window.detailData = (.+?)$', html).group(1)

The regex may change depending on what code is on the page, but I think the logic is clear

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question