I want to extract \"SNG_TITLE\" and \"ART_NAME\" values from the code in \"script\" tag using BeautifulSoup in Python. (the whole script is too long to paste)
If my understanding is correct, you want only the script element with "SNG_TITLE" in it.
You can use re
and get only the script element with the fields of your interest as follows:
import requests
from bs4 import BeautifulSoup
import re
base_url = 'https://www.deezer.com/en/profile/1589856782/loved'
r = requests.get(base_url)
soup = BeautifulSoup(r.text, 'html.parser')
user_name = soup.find(class_='user-name')
print(user_name.text)
for script in soup(text=re.compile(r'SNG_TITLE' )):
print(script.parent)
EDIT:
@furas answer is the complete solution using json
to find the 'SNG_TITLE' and 'ART_TITLE'. My answer help you find only the script with 'SNG_TITLE'. You can combine both to get better code.