title: How to parse JavaScript code in html source in Python?
body: <p>I am trying to web scrape some data inside a JavaScript tag in a HTML source.</p>
  <p>The situation: I can get to the appropriate <code>&lt;script&gt;&lt;/script&gt;</code> tag. But inside that tag, there is a big string, which needs to be converted and then parsed so I can get the precise data that I need.</p>
  <p>The problem is: I don't know how to do that and can't find a clear and satisfying answer to do it.</p>
  <p>Here is the code:</p>
  <p>My goal is to get this data: <code>&quot;xe7fd4c285496ab91&quot;</code> which is the identification number of the content, also called <code>&quot;contentId&quot;</code>.</p>
  <pre><code>import requests
  import bs4
  import re
  
  url = 'https://www.khanacademy.org/computing/computer-programming/programming/drawing-basics/pt/making-drawings-with-code'
  response = requests.get(url)
  soup = bs4.BeautifulSoup(response.text,'html.parser') # by the way I am not sure if this is the right way to parse the link
  
  item = soup.find(string=re.compile('contentId')) # with this line I can get directly to the exact JavaScript tag that I need
  
  print(item) # but as you can see, it's a pretty big string, and I need to parse it to get the desired data. But you can find that the desired data &quot;xe7fd4c285496ab91&quot; is in it.
  </code></pre>
  <p>I tried to use <code>json.parse()</code> but it is not working:</p>
  <pre><code>import json
  jsonparsed=json.parse(item)
  </code></pre>
  <p>Get this error:</p>
  <pre><code>AttributeError: 'NavigableString' object has no attribute 'json'
  </code></pre>
  <p>My question is:
  How can I get the desired data?
  Is there a function to convert the string into JavaScript so I can parse it? Or a way to convert this string into a JSON file?</p>
  <p>(Keep in mind that I will do this on multiple links with similar HTML/JavaScript).</p>