title: How to import a CSS table using BeautifulSoup when the table is a JSON object?
body: <p>I am trying to import a table from a url that is CSS heavy using BS4. Here is my code:</p>
  
  <pre><code>import csv
  from bs4 import BeautifulSoup
  import urllib.request as ur
  
  outfile = open(r"table_data.csv","w+",newline='')
  writer = csv.writer(outfile)
  
  html = ur.urlopen('url')
  
  tree = BeautifulSoup(html,"lxml")
  
  table_tag = tree.select(playersData)[0]
  tab_data = [[item.text for item in row_data.select("th,td")]
                  for row_data in table_tag.select("tr")]
  
  for data in tab_data:
      writer.writerow(data)
      print(' '.join(data))
  </code></pre>
  
  <p>The relevant part of the <code>tree</code>variable looks something like this:</p>
  
  <pre><code>&lt;div class="block"&gt;
  &lt;div class="block-content"&gt;
  &lt;div class="players" data-countinpage="10" data-pagination="true" id="league-players"&gt;&lt;/div&gt;
  &lt;script&gt;
          var playersData = JSON.parse('\x5B\x7B\x22id\x22\x3A\x221250\x22,\x22player_name\x22\x3A\x22Mohamed\x20Salah\x22,\x22games\x22\x3A\x2235\x22,\x22time\x22\x3A\x222869\x227D');
  &lt;/script&gt; &lt;/div&gt;
  &lt;/div&gt;
  </code></pre>
  
  <p>How do I import the <code>playersData</code>into a csv?</p>