title: Read contents of <script> with BeautifulSoup
body: <p>I have been trying to read the source of a website with the following:</p>
  
  <pre><code>import urllib2
  from BeautifulSoup import BeautifulSoup
  
  url     = 'http://www.myurl.com/'
  headers = {'User-Agent' : 'Mozilla/5.0'}
  request = urllib2.Request(url,None,headers)
  soup    = BeautifulSoup(urllib2.urlopen(request).read())
  </code></pre>
  
  <p>I further narrow it down as <code>scriptResults = soup('script',{'type' : 'text/javascript'})</code>. A sample of its contents is as follows:</p>
  
  <pre><code>scriptResults = [&lt;script type="text/javascript"&gt; ... &lt;/script&gt;,
                   ...,
                   &lt;script type="text/javascript"&gt;
                       //comment 1
                       $(function () {
                       //comment 2
                       var True = true, False = false;
                           func.start({
                               token1 : "...",
                               token2 : [...],
                               ...
                               tokenN : ["value1","value2",...,"valueK"],
                               ...
                           })
                       })
                   &lt;/script&gt;,
                   ...
                   ]
  </code></pre>
  
  <p>Now I'm interested in extracting the values in <code>tokenN</code>. I know that it is unique in the entire document and is present in all the webpages I'm trying to read. Further, the number of results in <code>scriptResults</code> can vary and the number of tokens can also vary, so I can't use a position index to access it. Also, I realize <code>BeautifulSoup</code> is a HTML parser and does not parse JS. How would I go about extracting this info using regex? </p>
  
  <p>If there isn't an easy way of getting them <em>all</em>, the following can be a compromise. <em>Most</em> of the <code>values</code> are of the form <code>"string1/xxxx/string2"</code>, where <code>xxxx</code> is some random SHA hash that's different for each and I can figure out the rest by other means. So if I can find only the ones that fit this pattern, it should be ok.</p>
  
  <hr>
  
  <p><strong>EDIT</strong></p>
  
  <p>In response to eyquem, I've uploaded the relevant portions before and after what I want to <a href="http://pastebin.com/AXGhHTS9" rel="nofollow">pastebin</a>. I'm interested in retrieving the values in <code>pageUrls</code>.</p>