Use python to execute javascript on a given list of websites and output result to a csv
<p>I have an input file which contains a list of URLs. I am trying to execute a script on each of  those URLs and output the result of that script to a CSV. </p>

<p>An example is trying to find if a given list of sites are using Google Analytics. The script below when run in the context of the page will return a JSON like "{'GA': true}".  </p>

<pre><code>var scripts = document.getElementsByTagName("script");
var source = [];
for (var i = 0; i &lt; scripts.length; i ++) {
    var s = scripts[i];
    if (!s.src) continue;
    source.push(s.src);
}
checkforGA();


function checkforGA() {
    var tools = {};
    for (var j = 0 ; j &lt; source.length; j ++) {
        if (/google-analytics.com\/(ga|urchin).js/i.test(source))
        {
            tools.GA = true;
            return JSON.stringify(tools);
        }
        else 
        {
            tools.GA = false;
            return JSON.stringify(tools);
        }
    }
}
</code></pre>

<p>My input is a csv file which has a list of sites</p>

<pre><code>Google, http://google.com
Wikipedia, http://wikipedia.com
Techcrunch, http://techcrunch.com
Stackoverflow, http://stackoverflow.com
Yahoo, http://yahoo.com
</code></pre>

<p>My desired output is </p>

<pre><code>Google, http://google.com, {'GA': false}
Wikipedia, http://wikipedia.com, {'GA': false}
Techcrunch, http://techcrunch.com, {'GA': true}
Stackoverflow, http://stackoverflow.com, {'GA': true}
Yahoo, http://yahoo.com, {'GA': false}
</code></pre>

<p>I am not sure if it is possible to run js from within a python script but i am looking for some idea on how to get started. </p>
