Answer the question
In order to leave comments, you need to log in
Answer the question
In order to leave comments, you need to log in
You need to use a library that is friendly with html.
For example beautifulsoup in a snake.
It can get any text from any tag, even script.
Decision:
script = soup.find('script',id='requirejs.config').string
<script type="application/json" id="requirejs.config">
and
you can do it like this:</script>
import json
from bs4 import BeautifulSoup
html = '''
<!DOCTYPE html>
<body>
<script type="application/json" id="requirejs.config">
{
"name": "John",
"age": 30,
"isAdmin": false,
"courses": ["html", "css", "js"],
"wife": null
}
</script>
</body>
</html>
'''
soup = BeautifulSoup(html,"html.parser")
script = soup.find('script',type="application/json")
my_json = str(script)[55:-12]
print(json.loads(my_json)['name'])
John
<script type="application/json" id="requirejs.config">
-12 - delete from the end
In my_json we will have everything that is inside the script tag. </script>
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question