Get Javascript code as string from url with Python
<p>I am trying to get a script written in Javascript from a URL with Python 2.7. I have tried using urllib, urllib2, and requests. They all return an empty string. The url contains no HTML elements it is just the javascript code.</p>

<p>Here's the link: <a href="http://go.pub2srv.com/apu.php?zoneid=676495" rel="nofollow noreferrer">http://go.pub2srv.com/apu.php?zoneid=676495</a></p>

<p>And what I have tried:</p>

<pre><code>import requests
r = requests.get('http://go.pub2srv.com/apu.php?zoneid=676495')
print r.text
</code></pre>

<p>returns <code>u' '</code>, same with urllib and urllib2.
Any ideas?</p>

<p><strong>UPDATE:</strong> OK I got it to work. Looks like the website was filtering user agents. 
This thread helped me out. <a href="https://stackoverflow.com/questions/25491872/python-request-geturl-returns-empty-content">Python request.get(url) returns empty content</a></p>

<p><code>import requests
url = 'http://go.pub2srv.com/apu.php?zoneid=676495'
user_agent = 'Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/36.0.1985.143 Safari/537.36'
headers = {'User-Agent': user_agent}
r = requests.get(url, headers=headers)</code></p>

<p>Thanks everyone.</p>