title: How to convert a BeautifulSoup tag to JSON?
body: <p>I have a type element, <code>bs4.element.Tag</code>, product of a web scraping, I usually do: <code>json.loads (soup.find ('script', type = 'application / ld + json'). Text)</code> , but on this page it only appears in: <code>&lt;script&gt; &lt;/script&gt;</code> so I had to do: <code>scripts = soup.find_all ('script')</code> until I get to the one that interests me: <code>script = scripts [18]</code>.</p>
  
  <p>The variable in question is <code>script</code>. My problem is that I want to access its attributes, for example <code>script ['goodsInfo']</code>, obviously being an element type <code>bs4.element.Tag</code>, try to do: <code>script.attrs</code> and return me <code>{}</code>. Then I tried to convert it to the type <code>json: json.loads (str (script))</code> and it throws me the <em>exception: 'JSONDecodeError: Expecting value: line 1 column 1 (char 0)'</em></p>
  
  <p>This is my code:</p>
  
  <pre><code>import json
  from bs4 import BeautifulSoup
  import requests
  url_aux = 'https://www.shein.com/Mock-neck-Brush-Stroke-Print-Bodycon-Dress-p-941649-cat-1727.html?scici=navbar_2~~tab01navbar04~~4~~real_1727~~~~0~~0'
  
  response = requests.get(url_aux)
  soup = BeautifulSoup(response.content, "html.parser")
  
  scripts = soup.find_all('script')
  script = scripts[18]
  
  print(json.loads(str(script)))
  #output: JSONDecodeError: Expecting value: line 1 column 1 (char 0)
  
  print(type(script))
  #output: bs4.element.Tag
  
  print(str(json.loads(str(script))))
  </code></pre>