Extract Text from Javascript using Python
<p>I've been looking at examples of how to do this but can't quite figure it out. I'm using beautifulsoup to scrape some data - I am able to use it to find the data I want, but it is contained in the following block of code. I'm trying to extract the timestamp information from it. I have a feeling regular expressions work here but I can't seem to figure it out - any suggestions?? </p>

<pre><code>    &lt;script class="code" type="text/javascript"&gt;
    $(document).ready(function(){
    line1 = [['2009-02-23 10 AM', 5203], ['2009-02-08 10 AM', 3898], ['2009-02-09 10 AM', 4923], ['2009-02-22 10 AM', 3682], ['2009-02-21 10 AM', 3238], ['2009-02-20 10 AM', 4648]];
    options1 = {
    etc other text
      }
    });
    &lt;/script&gt;
</code></pre>

<p>You can't use BS to get this data - BS works only with HTML/XML, not JavaScript. </p>

<p>You have to use <code>regular expressions</code> or standart string functions.</p>

<hr>

<p><strong>EDIT:</strong></p>

<pre><code>text = '''&lt;script class="code" type="text/javascript"&gt;
    $(document).ready(function(){
    line1 = [['2009-02-23 10 AM', 5203], ['2009-02-08 10 AM', 3898], ['2009-02-09 10 AM', 4923], ['2009-02-22 10 AM', 3682], ['2009-02-21 10 AM', 3238], ['2009-02-20 10 AM', 4648]];
    options1 = {
    etc other text
      }
    });
    &lt;/script&gt;'''

import re

re.findall("'([^']*)'", text)
</code></pre>

<p>result:</p>

<pre><code>['2009-02-23 10 AM',
 '2009-02-08 10 AM',
 '2009-02-09 10 AM',
 '2009-02-22 10 AM',
 '2009-02-21 10 AM',
 '2009-02-20 10 AM']
</code></pre>

javascript python beautifulsoup